使用實例:python xxx.py -u http://www.xxxx.net -f 字典.txt -n 10
-u 指定掃描網站;
-f 指定掃描字典;
-n 指定掃描線程數。
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # by 默不知然 2018-03-15 import threading from threading import Thread import time import sys import requests import getopt #創建類,並對目標網站發起請求 class scan_thread (threading.Thread): global real_url_list real_url_list = [] def __init__(self,url): threading.Thread.__init__(self) self.url = url def run(self): try: r = requests.get(self.url) print(self.url,'------->>',str(r.status_code)) if int(r.status_code) == 200: real_url_list.append(self.url) l[0] = l[0] - 1 except Exception as e: print(e) #獲取字典並構造url並聲明掃描線程 def url_makeup(dicts,url,threshold): global url_list global l url_list = [] l =[] l.append(0) dic = str(dicts) with open (dic,'r') as f: code_list = f.readlines() for i in code_list: url_list.append(url+i.replace('\r','').replace('\n','')) while len(url_list): try: if l[0] < threshold: n = url_list.pop(0) l[0] = l[0] + 1 thread = scan_thread(n) thread.start() except KeyboardInterrupt: print('用戶停止了程序,完成目錄掃描。') sys.exit() #獲取輸入參數 def get_args(): global get_url global get_dicts global get_threshold try: options,args = getopt.getopt(sys.argv[1:],"u:f:n:") except getopt.GetoptError: print("錯誤參數") sys.exit() for option,arg in options: if option == '-u': get_url = arg if option == '-f': get_dicts = arg if option == '-n': get_threshold = int(arg) #主函數,運行掃描程序 if __name__ == '__main__': get_args() url = get_url dicts = get_dicts threshold = get_threshold url_makeup(dicts,url,threshold) time.sleep(0.2) print('目標網站存在目錄: ','\n', real_url_list)
實例:如下是對http://www.gzgi.net 的目錄掃描。
參考鏈接:
州的先生bolg: http://zmister.com/archives/180.html