Skip to content

Instantly share code, notes, and snippets.

@fernandocarletti
Created June 20, 2018 17:25
Show Gist options
  • Save fernandocarletti/20c766ebb5e022572860bc6fcca94251 to your computer and use it in GitHub Desktop.
Save fernandocarletti/20c766ebb5e022572860bc6fcca94251 to your computer and use it in GitHub Desktop.
Check the DNS resolution time across many DNS servers.
#!/usr/bin/env bash
DEFAULT_HOSTNAME="pudim.com.br"
function help() {
echo "DNS Test"
echo
echo "Check the DNS resolution time across many DNS servers."
echo
echo "Usage:"
echo " dns_test.sh [-h] [--help] [hostname]"
echo
echo "The default hostname ($DEFAULT_HOSTNAME) will be used if the hostname is empty"
}
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help)
help
exit 0
;;
esac
shift
done
HOSTNAME=$1
if [ -z "$HOSTNAME" ]; then
HOSTNAME=$DEFAULT_HOSTNAME
fi
declare -A DNS_SERVERS=(
["Alternate DNS"]="198.101.242.72"
["Cloudfare"]="1.1.1.1"
["Comodo Secure DNS"]="8.26.56.26"
["DNS.WATCH"]="84.200.69.80"
["Dyn"]="216.146.35.35"
["Fourth Estate"]="45.77.165.194"
["FreeDNS"]="37.235.1.174"
["Google"]="8.8.8.8"
["GreenTeamDNS"]="81.218.119.11"
["Hurricane Electric"]="74.82.42.42"
["Level3"]="209.244.0.3"
["Neustar"]="156.154.70.1"
["Norton ConnectSafe"]="199.85.126.10"
["OpenDNS Home"]="208.67.222.222"
["OpenNIC"]="69.195.152.204"
["puntCAT"]="109.69.8.51 "
["Quad9"]="9.9.9.9"
["SafeDNS"]="195.46.39.39"
["SmartViper"]="208.76.50.50"
["UncensoredDNS"]="91.239.100.100"
["Verisign"]="64.6.64.6"
["Yandex.DNS"]="77.88.8.8"
)
echo Hostname: $HOSTNAME
echo
for DNS_SERVER in "${!DNS_SERVERS[@]}"; do
echo "Checking $DNS_SERVER @ ${DNS_SERVERS[$DNS_SERVER]}"
dig "$HOSTNAME" @"${DNS_SERVERS[$DNS_SERVER]}" | grep "Query time" | sed -E 's/;; //' || echo "Timed out"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment