python3 目录暴力扫描(多线程)

python3 目录暴力扫描(多线程)

以前写的py脚本,很烂。

普通版本:

import requests
import time

header = {
   'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; ',
}

if __name__ == '__main__':
    start = time.time()
    url = "http://127.0.0.1:8881/"
    director = '字典路径'
    file = open(director)
    for i in file:
        newUrl = url + i
        newUrl = newUrl.strip()
        respon = requests.get(newUrl,headers=header)
        if (respon.status_code == 200):
            print('[' + str(respon.status_code) + ']' + ":" + newUrl)
    end = time.time()
    print(end-start)

多线程版(不需要加锁):

import requests
import threading
import time

threads = []
thread_max = threading.BoundedSemaphore(500)

header = {
   'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; ',
}

def scan(url):
    try:
        respon = requests.get(url, headers=header)
        if (respon.status_code == 200):
            print('[' + str(respon.status_code) + ']' + ":" + url)
    except:
        pass
    thread_max.release()

def main(file,url):
    for i in file:  # newUrl的新名字hx
        newUrl = url+i
        newUrl = newUrl.strip()
        thread_max.acquire()
        t = threading.Thread(target=scan, args=(newUrl,))
        threads.append(t)
        t.start()
    for t in threads:
        t.join()

if __name__ == '__main__':
    start = time.time()
    url = "http://127.0.0.1:8881/"
    director = '字典路径'
    file = open(director)
    main(file,url)
    end = time.time()
    print(end-start)

你可能感兴趣的:(Python3)