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: 126.96.36.199 Address: 188.8.131.52#53 184.108.40.206.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?