Dig is a great tool, but most of its output is not very interesting. There are a bunch of command line options that I can never remember without a quick 'man dig' which always sounds a bit odd. So I whipped up a quick script. It takes a domain name as the argument, and then pumps out the Reverse IP lookup, Nameservers, and Mail servers with reverse lookup of their IPs.
#!/bin/bash
QUERYDOMAIN=$1
echo "Reverse IP:" echo " " `dig x +short $QUERYDOMAIN` echo "Nameservers" NAMESERVERS=`dig ns +short $QUERYDOMAIN | sed "s/^[0-9]* //g"` for SERVER in $NAMESERVERS; do echo " " $SERVER " = " `dig x +short $SERVER`; done echo "Mail Servers:" MAILSERVERS=`dig mx +short $QUERYDOMAIN | sed "s/^[0-9]* //g"` for SERVER in $MAILSERVERS; do echo " " $SERVER " = " `dig x +short $SERVER`; done
The output looks like this:
scripts/diggety.sh hp.com
Reverse IP:
15.216.110.22 15.216.110.139 15.216.110.140 15.192.45.21 15.192.45.22 15.192.45.138 15.192.45.139 15.216.110.21 15.240.238.51 15.240.238.55 15.193.112.21 15.193.112.23 15.201.49.21
Nameservers
ns1.hp.com. = 15.219.145.12
ns2.hp.com. = 15.219.160.12
ns3.hp.com. = 15.203.209.12
ns5.hp.com. = 15.195.192.37
ns6.hp.com. = 15.195.208.12
Mail Servers:
smtp.hp.com. = 15.193.32.72
I spent about 20 minutes writing the script, and then it just saved me about 30 minutes work when a client called, wanting to troubleshoot their mail servers over 20 domains. That's what bash scripts are all about … hope it saves you some time too.