From 2d1e7239b7f762e3d630ed6db002ee38f7739615 Mon Sep 17 00:00:00 2001 From: borekon Date: Mon, 23 Jan 2023 08:16:48 +0000 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20'test=5Fdns.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_dns.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test_dns.sh diff --git a/test_dns.sh b/test_dns.sh new file mode 100644 index 0000000..a0ec3bc --- /dev/null +++ b/test_dns.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# execute testdns.sh +command -v bc > /dev/null || { echo "bc was not found. Installing..."; sudo apt install -y bc; } +{ command -v drill > /dev/null && dig=drill; } || { command -v dig > /dev/null && dig=dig; } || { echo "dig was not found. Installing..."; sudo apt install -y dnsutils; } +NAMESERVERS=`cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/'` +PROVIDERS=" +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 +176.103.130.132#adguard +156.154.70.1#neustar +8.26.56.26#comodo +192.168.1.1#192.168.1.1 +94.140.14.140#adguard +77.88.8.8#yandex +64.6.64.6#verisign +130.59.31.248#switch-dns +216.146.35.35#dyn-dns +84.200.69.80#dns-watch +193.58.251.251#sky-dns +192.168.1.1#router +192.168.1.247#pihole local +" +# Dominios test. +DOMAINS2TEST="www.google.com amazon.com facebook.com www.youtube.com www.reddit.com wikipedia.org twitter.com gmail.com www.google.es whatsapp.com forocoches.es" +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 + 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 +exit 0;