Reputation: 105
I wanna convert a list of domain to the IP address using bash scripts in OSX.
I created a list file to present the domain line by line like this
www.google.com
www.yahoo.com
www.facebook.com
I used the following scripts to lookup the IP address:
#!/bin/bash
while read -r domain
do
echo `dig +short $domain`
done < list
where list is a file that contains those domain.
However, it end up only show a empty string.
But when I only query one domain, the command is okay.
dig +short www.google.com
> 216.58.221.132
Hope anyone can help me to figure out the problem. Thanks!
Upvotes: 2
Views: 537
Reputation: 5694
dig
has the -f
command line option to read a list of domain names from a file. From the manpage,
The -f option makes dig operate in batch mode by reading a list of lookup requests to process from the file filename. The file contains a number of queries, one per line. Each entry in the file should be organized in the same way they would be presented as queries to dig using the command-line interface.
Running
dig +short -f list
where the file named list contains
www.google.com
www.yahoo.com
www.facebook.com
will give you output like
74.125.239.114
74.125.239.112
74.125.239.116
74.125.239.113
74.125.239.115
fd-fp3.wg1.b.yahoo.com.
206.190.36.45
206.190.36.105
star.c10r.facebook.com.
31.13.77.6
Upvotes: 2