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: 18.104.22.168 Address: 22.214.171.124#53 126.96.36.199.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?