-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDNSbottom.py
executable file
·75 lines (63 loc) · 1.52 KB
/
DNSbottom.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
#!/usr/bin/python
# Filename: DNSbottom.py
import os,time
home = os.getenv("HOME")
path = home + "/CACHEHITRATE/"
f=open(path+'/bottom100.txt')
f1=open(path+'/bottom100.txt')
TTL=open(path+'/bottom_TTL.txt')
dname={}
ope=0
goog=0
isp=0
date = time.strftime('%m%d')
time = time.strftime('%H')
for i in range(1,101):
DN=f.readline().rstrip('\n') #Remove spaces and newlines
DN1=str(DN)
ttl=TTL.readline().rstrip('\n') #Remove spaces and newlines
dname[DN1]=ttl
if not os.path.exists(path):
os.mkdir(path)
f3=open(path+'/OpenResultBottom.txt','a')
f4=open(path+'/GoogleResultBottom.txt','a')
f5=open(path+'/ISPResultBottom.txt','a')
f3.write(date+time+',')
f4.write(date+time+',')
f5.write(date+time+',')
k=0
for line in f1.readlines():
t=line.rstrip('\n')
t1=str(t)
k+=1
i=str(k)
a=os.popen('dig @208.67.222.222 '+t+'|grep -o -m 1 \"'+dname[t1]+'\"')
result=a.read()
if(~(result.find(dname[t1]))):
f3.write('0,')
else:
f3.write('1,')
ope+=1
b=os.popen('dig @8.8.8.8 '+t+' +norecurse|grep -o \"ANSWER SECTION:\"')
result=b.read()
if(~(result.find('ANSWER SECTION'))):
f4.write('1,')
goog+=1
else:
f4.write('0,')
c=os.popen('dig '+t+' +norecurse|grep -o \"ANSWER SECTION:\"')
result=c.read()
if(~(result.find('ANSWER SECTION'))):
f5.write('1,')
isp+=1
else:
f5.write('0,')
ope1=str(ope)
goog1=str(goog)
isp1=str(isp)
f3.write(ope1+'\n')
f4.write(goog1+'\n')
f5.write(isp1+'\n')
f3.close()
f4.close()
f5.close()