O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



dnslook script
It ain't perfect. But had to write something to go look up nameservers at one point. Someone with more DNS brains than I can improve this. But it is mildly useful! I really didn't have time (at the time) to make it more-better ;-) We had two mail machines in the middle of moving them, thus mail. and mxrec. All you need to do is add or remove your servers you want to query for. It works generally except for those who reject queries!

Contributed by:
Unknown User anonymous2
[10/14/03 | Discuss (4) | Link to this hack]

#!/bin/bash
clear
# Remove previous run the FACIST way.
rm -rf /usr/local/sbin/dnsdump.txt
rm -rf /usr/local/sbin/NS.txt
 
# Obtain the NS server IP addresses only for the target domain.
dig $1 | grep IN | grep NS | awk '{print $5}' > /usr/local/sbin/NS.txt
 
# Get the number of lines in the file to read for puking data.
 
line_count=`wc NS.txt | awk '{print $1}'`
 
if [ "$line_count" -eq 0 ]; then 
 
clear
echo There are no NS records in domain "$1" or lookup request refused.
dig $1
exit 0
fi
 
# Get the stupid IP addresses for the dopey DNS servers.
 
for ns in `seq $line_count`
do
read ns
resolveip "$ns" | awk '{print $6}' >> /usr/local/sbin/dnsdump.txt
done < /usr/local/sbin/NS.txt
 
echo --------[ Looking up by nameservers for "$1" ]---------- 
dig $1 | grep IN | grep NS 
 
line_count=`wc /usr/local/sbin/dnsdump.txt | awk '{print $1}'`
 
for ip in `seq $line_count`
do
read ip 
 
# This next line was to test output. 
# echo "$ip"
 
# And now the ugly part.
 
echo -e\n
echo -e\n
# First the dot record
echo ------------------[ Using Nameserver IP "$ip" ]----------------------
echo -e\n
dotrec=`resolveip yoursite.com | awk '{print $6}'`
echo ----------[ Yoursite.Com should Reslove To: "$dotrec" ]
echo -e\n
echo -e\n
host yoursite.com "$ip"
echo -e\n
echo -e\n
dubdub=`resolveip www.yoursite.com | awk '{print $6}'`
echo ----------[ WWW.YourSite.Com should Resolve To: "$dubdub" ]
echo -e\n
echo -e\n
echo -e\n
host www.yoursite.com "$ip"
echo -e\n
post=`resolveip mail.yoursite.com | awk '{print $6}'`
echo ----------[ Mail.YourSite.Com should Resolve To: "$post" ]
echo -e\n
echo -e\n
echo -e\n
host mail.yoursite.com "$ip"
echo -e\n
mxrec=`resolveip mxrec.yoursite.com | awk '{print $6}'`
echo ----------[ MXRec.Yoursite.Com should Resolve To: "$mxrec" ]
echo -e\n
echo -e\n
echo -e\n
host mxrec.yoursite.com "$ip"
 
# Now we are done I hope
 
done < /usr/local/sbin/dnsdump.txt 
exit 0


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.