forked from cleanbrowsing/dnsperftest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnstest.sh
executable file
·71 lines (56 loc) · 1.71 KB
/
dnstest.sh
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
#!/bin/bash
command -v bc > /dev/null || { echo "bc was not found. Please install bc."; exit 1; }
{ command -v drill > /dev/null && dig=drill; } || { command -v dig > /dev/null && dig=dig; } || { echo "dig was not found. Please install dnsutils."; exit 1; }
NAMESERVERS=`cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/'`
PROVIDERS="
1.1.1.1#cloudflare-1
1.0.0.1#cloudflare-2
8.8.8.8#google-1
8.8.4.4#google-2
9.9.9.9#quad9-1
149.112.112.112#quad9-2
208.67.220.220#opendns-1
208.67.222.222#opendns-2
199.85.126.20#norton
185.228.168.168#cleanbrowsing
77.88.8.7#yandex
176.103.130.132#adguard
156.154.70.3#neustar
8.26.56.26#comodo
4.2.2.4#level3-1
4.2.2.2#level3-2
195.46.39.39#safedns-1
195.46.39.40#safedns-2
64.6.64.6#verisign-1
64.6.65.6#verisign-2
"
# Domains to test. Duplicated domains are ok
DOMAINS2TEST="www.google.com amazon.com facebook.com www.youtube.com www.reddit.com wikipedia.org twitter.com gmail.com www.google.com whatsapp.com"
totaldomains=0
printf "%-18s" ""
for d in $DOMAINS2TEST; do
totaldomains=$((totaldomains + 1))
printf "%-8s" "test$totaldomains"
done
printf "%-8s" "Average"
echo ""
for p in $NAMESERVERS $PROVIDERS; do
pip=${p%%#*}
pname=${p##*#}
ftime=0
printf "%-18s" "$pname"
for d in $DOMAINS2TEST; do
ttime=`$dig +tries=1 +time=2 +stats @$pip $d |grep "Query time:" | cut -d : -f 2- | cut -d " " -f 2`
if [ -z "$ttime" ]; then
#let's have time out be 1s = 1000ms
ttime=1000
elif [ "x$ttime" = "x0" ]; then
ttime=1
fi
printf "%-8s" "$ttime ms"
ftime=$((ftime + ttime))
done
avg=`bc -lq <<< "scale=2; $ftime/$totaldomains"`
echo " $avg"
done
exit 0;