Bulk Domain Record Lookups with Bash

Looking up domain records is a common daily task. Most of the time I use a website called MX Toolbox. That works great for single lookup. On occasion I need to do a bulk lookup for group of websites. While there are some websites that do bulk I found the best way is to simply run some scripts from the command line.

Bulk WHOIS lookup

Create a file named grab_whois.sh with the following. Change the input to include a list of your domains separated by spaces. 

input=(apple.com google.com microsoft.com)
output=whois_output.txt

# clears previous output
> $output

# bulk whois
while read p; do

    echo "Processing" $p

    # Send whois results to file
    whois $p >> $output

done <<< ${input[@]}

Running grab_whois.sh will output the following: https://cloudup.com/cNRZA_z-pUK.

Bulk nameserver lookup

Next let’s look at doing a nameserver lookup. The process is the same. Create a script called grab_ns.sh and put in following changing the input to the domains you wish to check:

input=(apple.com google.com microsoft.com)
output=ns_output.txt

# clears previous output
> $output

# bulk nslookup
while read p; do

    echo "Processing" $p

    # Send nameserver results to file
    host -t NS $p >> $output

done <<< ${input[@]}

This will output the following.

apple.com name server adns2.apple.com.
apple.com name server adns1.apple.com.
apple.com name server nserver6.apple.com.
apple.com name server nserver5.apple.com.
apple.com name server nserver2.apple.com.
apple.com name server nserver3.apple.com.
apple.com name server nserver.apple.com.
apple.com name server nserver4.apple.com.
google.com name server ns3.google.com.
google.com name server ns1.google.com.
google.com name server ns4.google.com.
google.com name server ns2.google.com.
microsoft.com name server ns2.msft.net.
microsoft.com name server ns3.msft.net.
microsoft.com name server ns4.msft.net.
microsoft.com name server ns1.msft.net.

Bulk other records types

This script can easily be adapted for any other record type by changing the line host -t NS $p >> $output. Here are a few common types.

host -t CNAME example.com
host -t MX example.com
host -t A example.com
host -t TXT example.com