I'm trying to produce a list of all the possible ip addresses for a given domain name. I think I'm close but don't know what I'm missing (or if there is a better way).
First I create a list of variations of the domain like so:
webkinz.com
www.webkinz.com
I then loop over this list and run dig on each variation like so:
while read domain; do
IPs=`dig $domain | grep $domain | grep -v ';' | awk '{ print $5 }'`;
echo " ${IPs}" >> /tmp/IPs; #array
done < /tmp/mylist
sort -u /tmp/IPs > /tmp/TheIPs; #remove duplicates
cat /tmp/TheIPs| tr -d "\n" > /tmp/IPs #remove new lines (making it 1 long line)
My IPs file looks like this:
66.48.69.100 www.webkinz.com.edgesuite.net.a1339.g.akamai.net.
Only 3 problems. :-(
dig www.webkinz.com
are missing.So, how should I do this? Do I somehow figure out if dig returned another domain instead of an ip address and run dig on that domain? Do I just ignore domain names returned from dig and figure the ip addresses is sufficient? I want to catch every ip address that will resolve to the domain if possible. I didn't think it should be this hard. Any ideas?
In order to get just the IP addresses, use dig +short
:
#!/bin/bash
while read -r domain
do
dig +short "$domain"
done < /tmp/mylist | sort -u | awk '{printf "%s ", $0} END {printf "\n"}' > outputfile
or
#!/bin/bash
echo $(xargs -a /tmp/mylist dig +short | sort -u) > outputfile
Using echo with an unquoted argument drops the newlines except at the end.
You don't need any intermediate variables or temporary files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With