· 8 years ago · Jun 02, 2018, 07:02 AM
1#!/bin/bash
2
3#Check for required utilities
4if ! which bc > /dev/null
5 then
6 echo "bc was not found. Please install bc."
7 exit 1
8fi
9
10if ! which dig > /dev/null
11 then
12 if which drill > /dev/null
13 then
14 alias dig="drill"
15 else
16 echo "neither dig nor drill was not found. Please install dnsutils or ldns."
17 exit 1
18 fi
19fi
20
21
22PROVIDERS="
231.1.1.1#cloudflare
241.0.0.1#cloudflare2nd
258.8.8.8#google
268.8.4.4#google2nd
279.9.9.9#quad9
28208.67.222.123#opendns
29199.85.126.20#norton
30185.228.168.168#cleanbrowsing
3177.88.8.7#yandex
32176.103.130.132#adguard
33156.154.70.3#neustar
348.26.56.26#comodo
35"
36
37# Domains to test. Duplicated domains are ok
38DOMAINS2TEST="www.google.com amazon.com facebook.com www.youtube.com www.reddit.com wikipedia.org twitter.com gmail.com www.google.com whatsapp.com"
39
40
41totaldomains=0
42printf "%-15s" ""
43for d in $DOMAINS2TEST; do
44 totaldomains=$((totaldomains + 1))
45 printf "%-8s" "test$totaldomains"
46done
47printf "%-8s" "Average"
48echo ""
49
50
51for p in $PROVIDERS; do
52 pip=`echo $p| cut -d '#' -f 1`;
53 pname=`echo $p| cut -d '#' -f 2`;
54 ftime=0
55
56 printf "%-15s" "$pname"
57 for d in $DOMAINS2TEST; do
58 ttime=`dig +stats @$pip $d |grep "Query time:" | cut -d : -f 2- | cut -d " " -f 2`
59 if [ -z "$ttime" ]; then
60 #let's have time out be 1s = 1000ms
61 ttime=1000
62 fi
63 printf "%-8s" "$ttime ms"
64 ftime=$((ftime + ttime))
65 done
66 avg=`bc -lq <<< "scale=2; $ftime/$totaldomains"`
67
68 echo " $avg"
69done
70
71
72exit 0;