How to use nslookup or dig to find multiple hosts (batch-type process)

Kurt Boyack kboyack at gmail.com
Tue Dec 27 19:06:34 UTC 2005


On 23 Dec 2005 18:28:06 -0800, Jim_4649 at yahoo.com <Jim_4649 at yahoo.com> wrote:
> I'm new to this, so please help me if you can! Here's my problem: I
> have a long list of fully qualified hostnames in an ASCII text file
> (over 300 hostnames). I want to find the IP address of each of these
> boxes. I know how to do this one record at a time using nslookup, but
> that would take forever.
>
> Can anyone tell me if there is some sort of batch file I can write, or
> some sort of batch function (using nslookup, dig or whatever) that
> would allow me to query the name server for all these hosts, using my
> list as the input? Of course I would want to pipe the results to
> another text file, but that part seems simple enough. Any help or
> suggestions would be greatly appreciated! Thanks a lot.

The host command is better suited for this than nslookup or dig.
Assuming you have it you could run:

while read HOST
do
    host $HOST
done < your_file > your_new_file

This would provide output like the following:

hp.com has address 192.6.234.18
hp.com has address 192.6.234.19
hp.com has address 192.6.165.40
hp.com has address 192.6.234.17
cisco.com has address 198.133.219.25
yellow.com has address 72.5.55.9
blue.com has address 80.245.197.244
green.com has address 63.146.163.45
red.com has address 65.61.174.178
brown.com has address 64.202.189.149

Getting the same results with nslookup would be a lot harder.



More information about the bind-users mailing list