-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathdnstest_random
More file actions
88 lines (74 loc) · 2.75 KB
/
Copy pathdnstest_random
File metadata and controls
88 lines (74 loc) · 2.75 KB
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
#!/usr/bin/env bash
command -v expr > /dev/null || { echo "expr was not found. Please install expr."; 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; }
# Local DNS resolvers
NAMESERVERS=`cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/'`
# Upstream DNS resolvers
# Non-standard ports may be specified e.g. 127.0.0.1:5353#mydns
PROVIDERS="
127.0.0.1:5353#openwrt_cryptdns
4.2.2.1#level3
8.8.8.8#google
9.9.9.9#quad9
208.67.222.123#opendns
199.85.126.20#norton
185.228.168.168#cleanbrowsing
8.26.56.26#comodo
176.103.130.130#adguard
176.103.130.132#adguard_family
1.1.1.1#cloudflare
1.1.1.2#cloudflare_family
8.8.8.8#google
"
# Number of domains to test
NUM_DOMAINS2TEST=20
# Random domains to choose from
RANDOM_DOMAINS=(
`curl -sS https://raw.githubusercontent.com/opendns/public-domain-lists/master/opendns-top-domains.txt`
`curl -sS https://raw.githubusercontent.com/opendns/public-domain-lists/master/opendns-random-domains.txt`
)
heading="DOMAINS TO TEST: "; echo -n "$heading"
results_indent=$((${#heading} - 3))
results_tempfile=`mktemp`
domains2test=""
num_random_domains=${#RANDOM_DOMAINS[*]}
for ((i=1; i <= $NUM_DOMAINS2TEST; i++)); do
if [ $i -gt 1 ]; then
printf "%-${#heading}s" ""
fi
domain_id=`printf "%5s" "($i) "`; echo -n "$domain_id"
domain_heading=" $domain_id"
results_header="$results_header$domain_heading"
random_domain=${RANDOM_DOMAINS[$RANDOM % num_random_domains]}; echo $random_domain
domains2test="$domains2test $random_domain"
done
avg_heading=" AVERAGE"
results_header="$results_header$avg_heading"
printf "\n%-${results_indent}s" ""
echo "$results_header"
for p in $PROVIDERS $NAMESERVERS; do
pip=${p%%#*}
[[ "$pip" =~ [:] ]] && pip="${pip%%:*} -p ${pip##*:}"
pname=${p##*#}
ftime=0
printf "%-${results_indent}s" "$pname"
for d in $domains2test; do
ttime=`$dig +tries=1 +time=2 +stats @${pip/:/" -p"} $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=100 #eliminate bias of shitty webpages noone will visit anyway
elif [ "x$ttime" = "x0" ]; then
ttime=1
fi
printf "%${#domain_heading}s" "$ttime ms"
ftime=$((ftime + ttime))
done
avg=$(expr $ftime / $NUM_DOMAINS2TEST)
printf "%${#avg_heading}s" $avg | tee -a $results_tempfile
printf "\n"
printf "ms ........................... $pname\n" >> $results_tempfile
done
echo -e "\n$(date) TOP:" | tee -a /reports/${0##*/}.log
#echo "$results_header"
sort -n $results_tempfile | tee -a /reports/${0##*/}.log
rm $results_tempfile