forked from cleanbrowsing/dnsperftest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnstest.sh
executable file
·94 lines (71 loc) · 2.27 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
command -v bc > /dev/null || { echo "error: bc was not found. Please install bc."; exit 1; }
{ command -v drill > /dev/null && dig=drill; } || { command -v dig > /dev/null && dig=dig; } || { echo "error: dig was not found. Please install dnsutils."; exit 1; }
NAMESERVERS=`cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/'`
PROVIDERSV4="
1.1.1.1#CloudflareDNS
8.8.8.8#GooglePublicDNS
8.20.247.20#ComodoSecureDNS
9.9.9.9#Quad9
149.112.121.10#CIRA-CA_Shield
208.67.222.123#Cisco-OpenDNS
"
PROVIDERSV6="
2001:4860:4860::8888#GooglePublicDNS_v6
2606:4700:4700::1111#CloudflareDNS_v6
2620:10A:80BB::20#CIRA-CA_Shield_v6
2620:fe::fe#Quad9_v6
2620:119:35::35#Cisco-OpenDNS_v6
"
# Testing for IPv6
$dig +short +tries=1 +time=2 +stats @2a0d:2a00:1::1 www.google.com |grep 216.239.38.120 >/dev/null 2>&1
if [ $? = 0 ]; then
hasipv6="true"
fi
providerstotest=$PROVIDERSV4
if [ "x$1" = "xipv6" ]; then
if [ "x$hasipv6" = "x" ]; then
echo "error: IPv6 support not found. Unable to do IPv6 test."; exit 1;
fi
providerstotest=$PROVIDERSV6
elif [ "x$1" = "xipv4" ]; then
providerstotest=$PROVIDERSV4
elif [ "x$1" = "xall" ]; then
if [ "x$hasipv6" = "x" ]; then
providerstotest=$PROVIDERSV4
else
providerstotest="$PROVIDERSV4 $PROVIDERSV6"
fi
else
providerstotest=$PROVIDERSV4
fi
# Domains to test. Duplicated domains are ok
DOMAINS2TEST="www.amazon.com www.canada.ca fb.com google.com www.quebec.ca reddit.com twitter.com www.tiktok.com wikipedia.org"
totaldomains=0
printf "%-21s" ""
for d in $DOMAINS2TEST; do
totaldomains=$((totaldomains + 1))
printf "%-8s" "test$totaldomains"
done
printf "%-8s" "Average"
echo ""
for p in $NAMESERVERS $providerstotest; do
pip=${p%%#*}
pname=${p##*#}
ftime=0
printf "%-21s" "$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 -l <<< "scale=2; $ftime/$totaldomains"`
echo " $avg"
done
exit 0;