-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdns-bench.py
executable file
·53 lines (43 loc) · 962 Bytes
/
dns-bench.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
#!/usr/bin/env python3
#
# Benchmark DNS servers
import os
import sys
import subprocess
SERVERS = [
'8.8.8.8',
'8.8.4.4',
'1.1.1.1',
'1.0.0.1',
'208.67.222.222',
'208.67.220.220',
'156.154.70.1',
'156.154.71.1',
'178.22.122.100',
'185.51.200.2',
'185.55.226.26',
'185.55.225.25',
'185.231.182.126',
'37.152.182.112',
'10.104.88.8',
'10.104.88.9'
]
def sortByQueryTime(item):
return item[1]
def sortQuery(url):
sorted = []
for i in SERVERS:
output = subprocess.check_output(['dig', i, url], shell=True, text=True)
sorted.append( [i, output.rfind("Query time:")] )
sorted.sort(key=sortByQueryTime)
return sorted
if __name__== "__main__":
url = None
if len(sys.argv) < 2:
url = 'google.com'
else:
url = sys.argv[1]
print('URL:', url)
query = sortQuery(url)
for i in query:
print('%-20s %i ms'%(i[0], i[1]))