-
Notifications
You must be signed in to change notification settings - Fork 80
/
gwhatweb.py
75 lines (66 loc) · 2.01 KB
/
gwhatweb.py
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
import requests
import json,hashlib,sys
import gevent
from gevent import monkey
monkey.patch_all()
from gevent.queue import Queue
import time
class gwhatweb(object):
def __init__(self,url):
self.tasks = Queue()
self.url = url.rstrip("/")
fp = open('data.json')
webdata = json.load(fp, encoding="utf-8")
for i in webdata:
self.tasks.put(i)
fp.close()
print("webdata total:%d"%len(webdata))
def _GetMd5(self,body):
m2 = hashlib.md5()
m2.update(body.encode("utf8"))
return m2.hexdigest()
def _clearQueue(self):
while not self.tasks.empty():
self.tasks.get()
def _worker(self):
data = self.tasks.get()
test_url = self.url + data["url"]
rtext = ''
try:
r = requests.get(test_url,timeout=10)
if (r.status_code != 200):
return
rtext = r.text
if rtext is None:
return
except:
rtext = ''
if data["re"]:
if (rtext.find(data["re"]) != -1):
result = data["name"]
print("CMS:%s Judge:%s re:%s" % (result, test_url, data["re"]))
self._clearQueue()
return True
else:
md5 = self._GetMd5(rtext)
if (md5 == data["md5"]):
result = data["name"]
print("CMS:%s Judge:%s md5:%s" % (result, test_url, data["md5"]))
self._clearQueue()
return True
def _boss(self):
while not self.tasks.empty():
self._worker()
def whatweb(self,maxsize=100):
start = time.clock()
allr = [gevent.spawn(self._boss) for i in range(maxsize)]
gevent.joinall(allr)
end = time.clock()
print ("cost: %f s" % (end - start))
if __name__ == '__main__':
if len(sys.argv) < 2:
print("usag:python gwhatweb.py http://www.xxx.com")
else:
url = sys.argv[1]
g = gwhatweb(url)
g.whatweb(1000)