I'm trying to find out how to take in a hostname and pop out an ip address (reverse dns lookup).
I came up with this but I'm not too sure it's safe across different linux distros:
nslookup $ip|grep "name ="|sed 's/^.*name = //'| sed '$s/\.$//'
It appears to be okay. The call to nslookup gives:
$ nslookup 127.0.0.1 Server: 220.127.116.11 Address: 18.104.22.168#53 22.214.171.124.in-addr.arpa name = localhost.
So we grep to remove the lines that don't give the hostname. Then we use said to remove everything before "name = " and remove the . at the end. If there are more than one line for whatever reason, then we just take the first one only. That gives 'localhost' There must be some better way to do this?