利用python3 實現網站資源探測工具


使用實例: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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM