Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LucaTNT
Created May 1, 2016 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucaTNT/0762b7af6bdf1a0bc2db53531a363a8b to your computer and use it in GitHub Desktop.
Save LucaTNT/0762b7af6bdf1a0bc2db53531a363a8b to your computer and use it in GitHub Desktop.
An old script I made years ago to compare the response times of two DNS servers
#!/bin/bash
# Author: Luca Zorzi <luca A_T tuttoeniente D_O_T net>
# License: CC Attribution (http://creativecommons.org/licenses/by/3.0/)
# Release date: 2009-12-13
# A little script to compare 2 DNS servers
if [[ "$#" != "2" ]]
then
echo "USAGE: $0 dns-server-1 dns-server-2"
exit 1
fi
start=`date +%s`
sites[1]="google.com"
sites[2]="ubuntu.com"
sites[3]="kernel.org"
dns_index=0;
for DNS in $1 $2
do
dns_index=`echo "$dns_index + 1" | bc`
dns_average[$dns_index]=0;
site_index=0;
for site in "${sites[@]}";
do
site_index=`echo "$site_index + 1" | bc`
total=0
for n in 1 2 3 4 5
do
result=`dig @$DNS $site| grep "Query time" | awk '{print $4}'`
total=`echo "$total + $result" | bc`
done
old_avg=${dns_average[$dns_index]}
dns_average[$dns_index]=`echo "$old_avg + $total" | bc`
done
total=${dns_average[$dns_index]}
average[$dns_index]=`echo "$total / ($site_index * 5)" | bc`
done
end=`date +%s`
runtime=`echo "$end - $start" | bc`
echo "TEST FINISHED"
echo "Run time: $runtime seconds"
echo "Testing $1 vs. $2"
echo "----------------------------------"
echo "$1 average: ${average[1]} ms"
echo "$2 average: ${average[2]} ms"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment