Script to find the name servers and A-records of multiple domains
Most of us must be familiar with the names 'dig' and 'whois'. If not, these are two commands used to find the details of domains. You just have to type in dig domainname
or whois domainname
to get a comprehensive set of info on the domain.
What if you have not just one or two domains to check about. How about a 1000 domains and you want to know the details of each?
Big job?? Don’t worry. You have the shell at your command. Just write a script to automate this for you.
Here’s such a script that I wrote for my uses. You just have to pass on the list of domains as input to this script, and it will give you the necessary info in another text file.The following is the script that does this function.
#!/bin/bash # dig $line +short >> ip address # whois $line >> Lists full details including the name servers # whois $line | grep "Name Server" | cut -d ":" -f 2 | sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta'` while read domain do echo $domain ipaddress=`dig $domain +short` nameserver=`whois $domain | grep "Name Server" | cut -d ":" -f 2 | sed 's/ //' | sed -e :a -e '$!N;s/ \n/,/;ta'` echo -e "$domain,$ipaddress,$nameserver" >> details.csv done domains.txt
Here the domains.txt is the input text document that will contain all your domains and the details.csv will be the output of the script, with the necessary details of all the domains passed.