Skip to content

Instantly share code, notes, and snippets.

@sahal
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save sahal/317bb8dca6719776e10f to your computer and use it in GitHub Desktop.

Select an option

Save sahal/317bb8dca6719776e10f to your computer and use it in GitHub Desktop.
#!/bin/bash
# ./auto_verify_dns.sh
# _very_ dumb way to verify that a list of dns servers work...
# by sahal
#
# use: ./auto_verify_dns.sh /full/path/to/dns/servers > ~/output
# requires timeout3 (set $W_TOUT) by Dimitry V Golovashkin (see Google)
# path to timeout3 - written by Dmitry V Golovashkin - via google
W_TOUT=/home/sahal/scripts/others/timeout3
fullpath_to_list_of_dns_servers=$1
#output=$2
a=($(cat $fullpath_to_list_of_dns_servers))
for i in $(seq 0 $((${#a[@]} - 1)))
do
$W_TOUT -t 5 nslookup baidu.com ${a[$i]} | grep answer\: > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo ${a[$i]} #>> $output
fi
done
#!/bin/bash
# ./auto_verify_dns.sh [server 10.0.0.12]
# desc: a quick test to see if a list (or one) of nameservers (IP/domains)
# are able to resolve a particular $domain within a set $timeoutsec
# by: Sahal Ansari (github@sahal.info)
# todo: check if nameserver given is a valid IP, print timeout lengths
#pick a domain to resolve (e.g. yahoo.com or google.com) and put it here:
domain=change.this.to.something.local
# full path to timeout3
# https://github.com/jeuneS2/lemberg/blob/master/timeout3
timeout3=/home/user/timeout3.sh
timeoutsec=5
# a list of potential dns servers
dns=/home/user/listodnsservers
if [ ! -e $timeout3 ]; then
echo "OOps, You don't have timeout3"
echo "Get it: https://github.com/jeuneS2/lemberg/blob/master/timeout3"
exit 1
fi
function checkdns {
$timeout3 -t $timeoutsec nslookup $domain $1 > /dev/null 2>&1 && echo $1
}
function breaklist {
if [ ! -e "$dns" ]; then
echo "OOps, Cannot find your list of DNS servers!?"
exit 1
fi
# you can mess with the input file (or not)
# for server in $(cut -d, -f2 < $dns)
for server in $(cat $dns)
do
checkdns $server
done
}
case $1 in
server*)
checkdns $2
;;
*)
breaklist
;;
esac
@sahal
Copy link
Copy Markdown
Author

sahal commented Aug 22, 2014

See the updated version on my github: https://github.com/sahal/auto_verify_dns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment