The output:
larry@lapdog2:~$ ./dnscheck.sh
Usage: dnscheck [target_domain] | [dnsprovider dns_ip [additional_ips ...]]
Sun Jun 19 01:07:42 MST 2011
Resolving yahoo.com @ 8.8.8.8 Google (avg msecs)= 88.900
95 84 88 87 89 92 95 86 87 86
Resolving yahoo.com @ 8.8.4.4 Google (avg msecs)= 69.700
68 68 69 69 68 69 71 75 70 70
Resolving yahoo.com @ 208.67.222.222 Opendns (avg msecs)= 40.800
44 39 40 40 39 49 40 39 40 38
Resolving yahoo.com @ 208.67.220.220 Opendns (avg msecs)= 39.800
43 39 40 39 39 41 42 39 38 38
Resolving yahoo.com @ 205.171.3.65 Qwest (avg msecs)= 61.200
59 62 62 59 60 60 63 67 60 60
Resolving yahoo.com @ 205.171.2.65 Qwest (avg msecs)= 67.700
60 85 104 73 60 59 59 59 58 60
Resolving yahoo.com @ 97.64.183.164 Mediacom (avg msecs)= 77.600
76 76 76 76 75 75 80 79 82 81
Resolving yahoo.com @ 97.64.179.250 Mediacom (avg msecs)= 81.800
79 89 86 83 83 79 79 80 79 81
Resolving yahoo.com @ 68.105.28.11 Cox (avg msecs)= 101.000
101 100 100 101 100 100 102 101 103 102
Resolving yahoo.com @ 68.105.29.12 Cox (avg msecs)= 95.400
97 96 96 93 94 93 96 102 94 93
The script (it could certainly be improved):
larry@lapdog2:~$ cat dnscheck.sh
#!/bin/bash
#
## Adapted from http://www.webupd8.org/2010/09/determine-dns-query-duration-quick.html
## by Larry Thiel 09/26/2010 No Rights Reserved
## modified by LT 10/04/2010
## modified by LT 06/18/2011 to rearrange display lines (could make 2nd line optional)
function checkdns ()
{
local prov=$1
local serv=$2
local targ=$3
#whois ${serv} | grep NetName # not used but don't forget idea
x=0; queries=10
declare -a mtime
echo -n "Resolving ${targ} @ ${serv}"
for i in `seq $queries`
do
result=$( dig @${serv} $targ | grep "Query time" | cut -f 4 -d " " )
if [ ! $result ]
then result="9999"
fi
let mtime[i]=$result
let x+=$result
if [ $result == 9999 ]
then echo -n "-->Apparently ${serv} is not reachable"; logger -t dnscheck "Apparently ${serv} is not reachable";break
fi
done && echo -n " $prov (avg msecs)= " && echo "scale=3;($x/${i}) " | bc
x=0
echo -n " "
for i in `seq $queries`
do
let x+=mtime[i]
echo -n "${mtime[i]} "
done && echo
}
## Main body begins. Until arg processing improved, always display usage info
##
echo "Usage: dnscheck [target_domain] | [dnsprovider dns_ip [additional_ips ...]]"
echo
## If the user provides a single argument, assume it is a target to lookup
## otherwise assume it is a provider name followed by the IPs of their DNS servers
provider=localhost; server=127.0.0.1; target=yahoo.com
#echo "---- debug: argument count=" $#
echo -n " " && date
if [ $# == 1 ]
then
target=$1;
elif [ $# > 1 ]
then
provider=$1; shift
while [ $1 ]
do
server=$1
checkdns ${provider} ${server} ${target}
shift
done
fi
## In all cases check known servers for comparison purposes
## Note: it would be good to make this optional or only for specific provider(s)
checkdns Google 8.8.8.8 ${target}
checkdns Google 8.8.4.4 ${target}
checkdns Opendns 208.67.222.222 ${target}
checkdns Opendns 208.67.220.220 ${target}
checkdns Qwest 205.171.3.65 ${target}
checkdns Qwest 205.171.2.65 ${target}
checkdns Mediacom 97.64.183.164 ${target}
checkdns Mediacom 97.64.179.250 ${target}
checkdns Cox 68.105.28.11 ${target}
checkdns Cox 68.105.29.12 ${target}
larry@lapdog2:~$
--
Dazed_75 a.k.a. Larry
The spirit of resistance to government is so valuable on certain occasions, that I wish it always to be kept alive.
- Thomas Jefferson