Friday, June 26, 2015

Resolve IPs from list of domains

A command to resolve IPs from a list of domains, without impacting a DNS server too much.

I needed to resolve the IPs for a list of 900+ domains and didn't want to impact our DNS servers too much, so I improved on commands and suggestions that I found online; in particular a command from user alanwilliamson on http://www.commandlinefu.com/commands/view/3066/resolve-a-list-of-domain-names-to-ip-addresses


list2.txt is a simple text file with a domain per line.

$ awk < list2.txt '{ while( ("resolveip -s " $1 " 2>/dev/null; sleep 1;" | getline tmp ) > 0){ print $1 "," tmp} }'


For a given list of:

domain1.com
domain2.com
www.domain3.com

The output would look like: 

domain1.com,xxx.xxx.xxx.xxx
domain2.com,xxx.xxx.xxx.xx2
www.domain3.com,xxx.xxx.xxx.xx3


A slightly improved version which times the command, outputs to a file and flushes the buffer immediately so that the following "tail" command will be in real-time. 

$ time awk < list.txt '{ while( ("resolveip -s " $1 " 2>/dev/null; sleep 1;" | getline tmp ) > 0){ print $1 "," tmp; fflush(stdout) } }' > report.txt

You can then watch the growth of report.txt or set a tail -f on it to watch the progress:

$ tail -f ./report.txt