python后台扫描脚本

python 后台扫描脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding:utf-8 -*-
import urllib
import time
import threading

url = raw_input("输入你要扫描的网址:")
txt = raw_input("输入字典(php.txt):")

# 保存存在的后台地址
open_url = []
all_url = []

# 建立线程列表
threads = []

# 从字典中读取每一行与url组合,然后添加到all_url
def search_url(url,txt):
with open(txt,'r') as f:
for each in f:
each = each.replace('\n','')
urllist = url + each
all_url.append(urllist)


# 处理url
def handle_url(urllist):
print ("查找:"+urllist+'\n')
try:
req = urllib.urlopen(urllist)

# 判断返回码
if req.getcode() == 200:
open_url.append(urllist)

if req.getcode() == 301:
open_url.append(urllist)

except:
pass


# 主函数
def main():
search_url(url,txt)
# 多线程处理
for each in all_url:
t = threading.Thread(target= handle_url, args=(each,))
threads.append(t)
t.start()


# 线程等待

for t in threads:
t.join()


# 扫描成功和不成功的回显

if open_url:
print ("扫描成功,网站后台地址为:")
for each in open_url:
print ("[+]"+each)

else:
print ("没有扫到网站后台,字典不给力啊")


if __name__ =="__main__":

# 判断运行时间
start = time.clock()
main()
end = time.clock()
print ("The function spend time is %.3f seconds" %(end-start))