Python多线程目录扫描器,代码很简单,不过也花了我很多时间。
遇到文件如下:
- 多线程执行问题
- 队列执行问题
- 编码问题
- 目录问题
- 自己逻辑问题
报告长官,总结完毕,以下是成果,请长官查收: # coding:utf-8 import requests import threading import Queue import sys url_list = Queue.Queue() mutex = threading.Lock() def path(url): with open("./path.txt") as Path: # ./path.txt 为字典地址,请使用相对目录 for i in Path: yield url + i.split("\n")[0] def Handle_open(url): for i in path(url): url_list.put(i) def is_200(url): Handle_open(url) try: while not url_list.empty(): mutex.acquire() try: r = requests.get(url_list.get(), allow_redirects=False, timeout=2, headers={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/45.0.2454.101 Safari/537.36"}) if r.status_code == 200 or r.status_code == 302: print "\n[+] %s code: %s" % (url_list.get(), r.status_code) finally: mutex.release() except: pass def run_main(url, thread_int): for i in range(thread_int): i = threading.Thread(target=is_200, args=(url,)) i.start() i.join() if __name__ == ‘__main__‘: if len(sys.argv) < 2 or len(sys.argv) > 3: print u‘‘‘程序使用请转至博客:www.hack-sb.com‘‘‘ run_main(sys.argv[1], int(sys.argv[2]))
时间: 2024-11-05 12:25:54