python实现简单的目录扫描工具
1 import requests 2 import threadpool 3 4 # 响应码 5 code = [200, 403] 6 7 # 获取用户输入的URL 8 url = input("请输入待扫描的网址:") 9 if not url.startswith("http"): 10 print("请输入有效的网址(包括http或https)") 11 exit() 12 13 # 使用上下文管理器打开输出文件 14 with open("url.txt", 'w+', encoding='utf-8') as ff: 15 lists = [] 16 17 # 执行zidian()这个函数,利用for循环把php.txt里面的路径都读到lists这个列表里 18 def zidian(): 19 with open('php.txt', 'r', encoding='utf-8') as f: 20 for d in f: 21 dir = d.strip() 22 lists.append(dir) 23 24 # 目录扫描函数 25 def dirscan(lujing): 26 try: 27 res = requests.get(url + lujing, timeout=3) 28 if res.status_code in code: 29 ff.write(lujing + '\n') 30 print(f"{res.status_code}: {url + lujing}") 31 except requests.exceptions.RequestException as e: 32 print(f"请求失败: {e}") 33 34 # 加载字典 35 zidian() 36 37 # 使用线程池进行多线程扫描 38 pool = threadpool.ThreadPool(10) 39 reqs = threadpool.makeRequests(dirscan, lists) 40 [pool.putRequest(req) for req in reqs] 41 pool.wait()
借鉴https://www.freebuf.com/sectool/259715.html这里的原文修改