-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathparse_target.py
52 lines (46 loc) · 1.27 KB
/
parse_target.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
import datetime
import hashlib
import re
import socket
import time
from urlparse import urlparse
import pymongo
import requests
from bson import ObjectId
temp_cli = pymongo.MongoClient()['demo']['temp']
cli = pymongo.MongoClient()['demo']['data']
def do_sth(i):
def get_ip(host):
try:
return socket.gethostbyname(host)
except Exception:
return None
host = urlparse(i)[1]
ip = get_ip(host)
title = None
if ip:
try:
req = requests.get(i, timeout=10)
except Exception as e:
return
pass
try:
req.encoding = req.apparent_encoding
title = re.findall('<title>(.*?)</title>', req.text, flags=re.I | re.M)
if title:
title = title[0]
uniq_hash = hashlib.md5(req.content).hexdigest()
cli.insert_one(
{'target': i, 'ip': ip, 'title': title, 'add_time': datetime.datetime.utcnow(), 'domain': host,
'hash': uniq_hash
}
)
except Exception as e:
print e
pass
while True:
for i in temp_cli.find({}):
do_sth(i['target'])
temp_cli.remove({'_id': ObjectId(i['_id'])})
time.sleep(10)
print 'fick'