局域网存活主机扫描
import re
from functools import partial
from multiprocessing.dummy import Pool as ThreadPool
import time
import os
def ping(num,ip):
a = os.popen('ping '+ip+str(num)).read()
text=re.findall("TTL=(.*?)\n",a)
if text==[]:
s="no"
else:
s=text[0]
print(ip+str(num)+" "+s)
os.close
if __name__=="__main__":
t=[]
ip="172.19.20."
for i in range(0,256):
t.append(i)
pool=ThreadPool(512)
pool.map(partial(ping,ip=ip),t)#t 对应第一个参数
pool.close()
pool.join()
url端口扫描
import requests
import re
import urllib
from urllib.request import urlopen
from functools import partial
from multiprocessing.dummy import Pool as ThreadPool
def pt(port,url):
url=url+":"+str(port)
try:
req=requests.get(url)
except:
req="no"
print(req,i)
if __name__=="__main__":
t=[]
url="http://127.0.0.1"
for i in range(0,256):
t.append(i)
pool=ThreadPool(512)
pool.map(partial(pt,url=url),t)#t 对应第一个参数
pool.close()
pool.join()