import requests import threadpool # 响应码 code = [200, 403] # 获取用户输入的URL url = input("请输入待扫描的网址:") if not url.startswith("http"): print("请输入有效的网址(包括http或https)") exit() # 使用上下文管理器打开输出文件 with open("url.txt", 'w+', encoding='utf-8') as ff: lists = [] # 执行zidian()这个函数,利用for循环把php.txt里面的路径都读到lists这个列表里 def zidian(): with open('php.txt', 'r', encoding='utf-8') as f: for d in f: dir = d.strip() lists.append(dir) # 目录扫描函数 def dirscan(dir): try: res = requests.get(url + dir, timeout=3) if res.status_code in code: ff.write(dir + '\n') print(f"{res.status_code}: {url + dir}") except requests.exceptions.RequestException as e: print(f"请求失败: {e}") # 加载字典 zidian() # 使用线程池进行多线程扫描 pool = threadpool.ThreadPool(10) reqs = threadpool.makeRequests(dirscan, lists) [pool.putRequest(req) for req in reqs] pool.wait()
借鉴https://www.freebuf.com/sectool/259715.html这里的原文修改
标签:code,python,res,扫描,lists,url,目录,dir From: https://www.cnblogs.com/liuwangqingnian/p/18394701