本文来源吾爱破解论坛
本帖最后由 纸条 于 2019-9-20 13:49 编辑
2018年5月份写了一版,但是很慢,期间也改过很多版,但还是很慢。
2019年9月20日改了一下,先检测端口是否存活,存活了再去探测web:
使用方法:
url.py C:\Python36\test\url.txt
程序 链接文本路径(一行一个)
import requests
import queue
import re
import sys
import time
import threading
import telnetlib
from urllib.parse import urlparse
requests.packages.urllib3.disable_warnings()
class Waittask(threading.Thread):
def run(self):
self.telnet = telnetlib.Telnet()
while True:
if asset.qsize() < 100:
for i in range(500):
host = urlparse(waittask.get())
scheme = host.scheme
netloc = host.netloc
try:
if ':' in netloc:
Host = netloc.split(':')
self.telnet.open(Host[0],Host[1],timeout = 3)
asset.put('{}://{}:{}'.format(scheme,Host[0],Host[1]))
else:
self.telnet.open(netloc,80,timeout = 3)
asset.put('{}://{}'.format(scheme,netloc))
except Exception as e:
pass
time.sleep(1)
class Asset(threading.Thread):
def run(self):
while True:
while not asset.empty():
url = asset.get()
try:
response = requests.get(url, verify=False, allow_redirects=False,timeout = 15)
try:
title = re.findall('<title>(.*?)</title>',response.text.lower())[0]
except Exception as e:
title = '获取标题失败'
print(response.status_code,response.url,title)
with open('survival.txt','a',encoding='gb18030') as cent:
cent.write('{}|{}|{}\n'.format(response.status_code,response.url,title))
except Exception as e:
pass
time.sleep(1)
class Check(threading.Thread):
def run(self):
while True:
time.sleep(10)
print('进度:{:.2%} 当前还有{}个端口开放检测,{}个WEB探测任务未完成!'.format(1-int(waittask.qsize())/sums,waittask.qsize(),asset.qsize()))
if __name__ == '__main__':
file = sys.argv[1]
waittask = queue.Queue()
asset = queue.Queue()
with open(file) as content:
for cent in content:
waittask.put(cent.strip())
sums = int(waittask.qsize())
for i in range(100):
Waittask_ = Waittask()
Waittask_.start()
for i in range(100):
Asset_ = Asset()
Asset_.start()
check = Check()
check.start()
版权声明:
本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。