-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsbench.py
executable file
·64 lines (55 loc) · 1.74 KB
/
dnsbench.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
#!/usr/bin/env python3
# coding=utf-8
from subprocess import PIPE, run
from statistics import mean
HOSTS = [
'www.bing.com',
'www.google.com',
'mail.google.com',
'www.youtube.com',
'www.amazon.com',
'www.amazonvideo.com',
'd2lkq7nlcrdi7q.cloudfront.net',
'www.walmart.com',
'www.facebook.com',
'connect.facebook.net',
'staticxx.facebook.com',
'bbc.com',
'www.theguardian.com',
'c.apple.news'
]
SERVERS = [
'8.8.8.8',
'8.8.4.4',
'68.94.156.1',
'68.94.157.1',
'208.67.222.222',
'208.67.220.220',
'129.250.35.250',
'129.250.35.251',
'172.17.0.30'
]
def main():
res = {}
for dns in SERVERS:
res[dns] = {'min': [], 'avg': [], 'max': [], 'stdev': []}
for rep in range(10):
for host in HOSTS:
for dns in SERVERS:
print(f'benching {host} via {dns}')
command = f'host -4 -t A {host} {dns} | awk \'/address/{{system("ping -i 0.1 -c 10 "$4" | grep round")}}\''
r = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
for line in r.stdout.strip().splitlines():
(tmin, tavg, tmax, tstdev) = line.split()[3].split('/')
res[dns]['min'].append(float(tmin))
res[dns]['max'].append(float(tmax))
res[dns]['avg'].append(float(tavg))
res[dns]['stdev'].append(float(tstdev))
print('')
print('server min avg max stdev')
for dns in res:
print(f"{dns} {mean(res[dns]['min']):.3f} {mean(res[dns]['avg']):.3f}",
f"{mean(res[dns]['max']):.3f} {mean(res[dns]['stdev']):.3f}")
print('')
if __name__ == '__main__':
main()