Last active
February 8, 2022 10:55
-
-
Save BertalanD/806168f1c7fb815124af458ce845da84 to your computer and use it in GitHub Desktop.
Benchmark public DNS resolvers against your own
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
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="$(grep '^nameserver' /etc/resolv.conf | cut -d " " -f 2 | sed 's/\(.*\)/&#&/')" | |
PROVIDERS=" | |
$(ip route | awk '/default/ { print $3 }')#gateway | |
1.1.1.1#cloudflare | |
4.2.2.1#level3 | |
8.8.8.8#google | |
9.9.9.9#quad9 | |
80.80.80.80#freenom | |
208.67.222.123#opendns | |
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 | |
" | |
# Domains to test. Duplicated domains are ok | |
TESTDOMAINS="www.google.com duckduckgo.com facebook.com www.youtube.com www.reddit.com wikipedia.org github.com docs.rs git.sr.ht stackoverflow.com wiki.archlinux.org protonmail.com crates.io danielbertalan.dev freenode.net" | |
totaldomains=0 | |
printf "%-18s" "" | |
for d in $TESTDOMAINS; 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 $TESTDOMAINS; do | |
# Sleeping to avoid possible anti-abuse | |
sleep 0.1 | |
ttime="$($dig +tries=1 +time=2 +dnssec +stats @$pip $d | grep "Query time:" | cut -d : -f 2- | cut -d " " -f 2)" | |
if [ -z "$ttime" ]; then | |
# let's have timeout be 1 s = 1000 ms | |
ttime=1000 | |
elif [ "x$ttime" = "x0" ]; then | |
ttime=1 | |
fi | |
printf "%-8s" "$ttime ms" | |
ftime=$((ftime + ttime)) | |
done | |
avg="$(echo "scale=2; $ftime/$totaldomains" | bc -lq)" | |
echo " $avg" | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment