Blog
Quick app to compare speed of dns servers
Submitted by cscutcher on Tue, 2009-02-03 18:16I wrote this little app to compare the speed of OpenDNS to my ISPs DNS server. Its far from bullet proof but someone might find it useful.
-
#!/bin/bash
-
-
function query_time
-
{
-
#Runs query and returns the time in msecs for the query
-
# query_time dns_server address
-
echo $(dig @$1 $2 +noall +stats | grep "Query time" | tr -d "\;\; Query time: " | tr -d " msec")
-
return $?
-
}
-
-
function total_time
-
{
-
#Returns the total time used for $3 queries
-
# total_time dns_server address number_of_queries
-
result=0
-
for i in `seq 1 $3`
-
do
-
time=$(query_time $1 $2)
-
result=$(($result+$time))
-
#Put a random wait between queries
-
sleep $(echo "$((RANDOM % 50)) / 100" | bc -l)
-
done
-
-
echo $result
-
return 0
-
}
-
-
#Address of servers to compare
-
dns_a="87.194.0.66"
-
dns_b="208.67.222.222"
-
-
#Stores scores
-
score_a=0
-
score_b=0
-
-
#Store totals
-
total_a=0
-
total_b=0
-
-
#Number of times to test each address
-
tries=20
-
-
#Start
-
echo "Running comparison;"
-
echo " DNS A = $dns_a"
-
echo " DNS B = $dns_b"
-
echo "--------------------"
-
-
#Load list of sites from file at $1
-
# File should contain list of domain names. One per line.
-
sites=$(cat $1 | tr '\n' ' ')
-
-
for site in $sites
-
do
-
result_a=$(total_time $dns_a $site $tries)
-
a_ave=$((result_a / tries))
-
((total_a+=result_a))
-
result_b=$(total_time $dns_b $site $tries)
-
b_ave=$((result_b / tries))
-
((total_b+=result_b))
-
-
if (($a_ave > $b_ave))
-
then
-
win_text="Win for B"
-
((score_b += 1))
-
else
-
if (($a_ave < $b_ave))
-
then
-
win_text="Win for A"
-
((score_a += 1))
-
else
-
win_text="Draw"
-
((score_a += 1))
-
((score_b += 1))
-
fi
-
fi
-
printf "%30.30s - a=%.3i ave=%.3i - b=%.3i ave=%.3i - %s\n" "$site" "$result_a" "$a_ave" "$result_b" "$b_ave" "$win_text"
-
done
-
-
-
#Compare number of sites that were quieried faster
-
printf "\n\n"
-
if (($score_a>$score_b))
-
then
-
win_text="DNS A wins"
-
else
-
if (($score_a<$score_b))
-
then
-
win_text="DNS B wins"
-
else
-
win_text="Draw"
-
fi
-
fi
-
-
echo "Queries"
-
printf " A = %.3i :: B = %.3i :: %s\n\n" "$score_a" "$score_b" "$win_text"
-
-
if (($total_a>$total_b))
-
then
-
win_text="DNS A wins"
-
else
-
if (($total_a<$total_b))
-
then
-
win_text="DNS B wins"
-
else
-
win_text="Draw"
-
fi
-
fi
-
-
echo "Total query time"
-
printf " A = %.3i :: B = %.3i :: %s\n\n" "$total_a" "$total_b" "$win_text"
| Attachment | Size |
|---|---|
| test-dns.sh | 2.31 KB |