Skip to content

Instantly share code, notes, and snippets.

@joeroback
Last active December 22, 2020 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeroback/031f8778f47072f15b4d23e85f66b52e to your computer and use it in GitHub Desktop.
Save joeroback/031f8778f47072f15b4d23e85f66b52e to your computer and use it in GitHub Desktop.
#!/usr/bin/env 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="
192.168.1.1#pfsense
192.168.42.42#pihole
1.1.1.1#cloudflare1
1.0.0.1#cloudflare2
8.8.8.8#google1
8.8.4.4#google2
9.9.9.9#quad9
"
# 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
for p in $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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment