-
Notifications
You must be signed in to change notification settings - Fork 100
/
request.py
executable file
·89 lines (84 loc) · 2.69 KB
/
request.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
76
77
78
79
80
81
82
83
84
85
86
87
88
# encoding=utf8
#date:2017-10-24
#function : request the data using domain
import MySQLdb
import platform
import warnings
import sys
reload(sys)
sys.setdefaultencoding('utf8')
warnings.filterwarnings("ignore")
def Parse_DnsFile(dnsfile,domainfile):
try:
DnsFile= open(dnsfile,'r')
except:
print 'DNS file not found'
print 'The file can be generate from the file DNS-Sniffer/RunSniffer.py'
Domain_Collect = open(domainfile,'w')
for line in DnsFile:
line = line.strip('\n')
#avoid top of the file and the space
if len(line)<7:
continue
else:
if 'IP Source' in line :
continue
line = line.strip()
line_parameter = line.split()
domain = line_parameter[3]
Domain_Collect.write(domain+'\n')
DnsFile.close()
Domain_Collect.close()
return True
def request_domain(DomainFile,ResultFile):
domain_file = open(DomainFile,'r')
result_file = open(ResultFile,'w')
result_file .write("Domain stamp source update_time")
db = MySQLdb.connect(user='root',db='TiDB',passwd='123456',host='192.168.9.12',charset='utf8')
cursor = db.cursor()
for domain in domain_file:
domain = domain.strip('\n').strip()
domain_option = "select * from domain_table where domain = '%s';"%domain
cursor.execute(domain_option)
raw_reply = cursor.fetchall()
if raw_reply == ():
continue
reply = raw_reply[0]
result = []
for each in reply:
result.append(each.encode('utf-8'))
domain = result[0]
update_time = result[1]
source = result[2]
stamp = result[3]
print '#**********************************************************************************#'
print ''
print 'warning :suspicous domain'
print 'domain :',domain
print 'stamp :',stamp
print 'source :',source
print 'data update time :',update_time
print ''
print '#**********************************************************************************#'
Result = "%s %s %s %s"%(domain,stamp,source,update_time)
result_file.write(Result)
db.close()
domain_file.close()
result_file.close()
return True
if __name__ == '__main__':
s=platform.system()
if cmp(s,"Windows")==0:
s = "输入DNS_Sniffer生成的文件(当前路径下),如‘Dns.txt’"
print s.decode('utf-8').encode('gbk')
rawfile = raw_input(">")
s = '开始解析--------------->>>>>>>'
print s.decode('utf-8').encode('gbk')
if Parse_DnsFile(rawfile,'domain_file.txt'):
request_domain('domain_file.txt','Result.txt')
else:
print "输入DNS_Sniffer生成的文件(当前路径下),如‘Dns.txt’"
rawfile = raw_input(">")
print '开始解析--------------->>>>>>>'
if Parse_DnsFile(rawfile,'domain_file.txt'):
request_domain('domain_file.txt','Result.txt')