Dns subnet: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(No difference)
|
Latest revision as of 17:41, 31 January 2011
#!/bin/bash
# find all known dns entries for a class C subnet
# subnet (e.g. 123.45.67)
subnet=123.45.67
host=/usr/bin/host
if [[ $host == "" ]]; then
echo "host program not found"
echo "aborting..."
exit 1
fi
if [[ ! -x $host ]]; then
echo "host program $host not executable"
echo "aborting..."
exit 1
fi
echo "Known DNS entries for subnet $subnet on `date`"
# main loop
for (( i=1; i <= 254; i++))
do
ip=${subnet}.$i
output=`$host $ip 2> /dev/null`
#echo "output is \"$output\""
notfound=`echo $output | grep "not found"`
if [[ -z $notfound ]]; then
hostname=`echo $output | awk '{print $5}'`
echo -e "${ip}\t${hostname}"
fi
done
exit 0