Quote:>I need a command line utility for converting IP addresses to
>host names. This utility needs to work from a script, so nslookup is
>not a particularly good choice. Is there a simple program that will
>do this for me?
- Your system might have 'host'. In which case, you just type
"host 127.0.0.1" and parse the output (unfortunately, output may
vary from Unix to Unix).
- You can use nslookup, as in
#! /bin/sh
namebyip ()
{
arpa=`
echo "$1" |
awk -F. '{ print $4"."$3"."$2"."$1".in-addr.arpa" }'
`
{ echo 'set q=any'; echo "$arpa" } |
nslookup |
grep "$arpa" |
sed -e 's/.* //'
}
namebyip 128.83.139.9
- It's also possible to do it in perl, by calling gethostbyname.
Quote:>I could also use one that converts from port number to service name.
Something like this:
#! /usr/local/bin/perl
{
$service = getservbyport ($_, 'tcp');
print "$_: $service\n";
}
Note, it's probably also possible to use perl converting from IP address
to IP hostname, using gethostbyaddr().
Hope that helps...
Adios,
Logan
--
Logan Shaw, Unix System Administrator
"Everything is a struggle in Unix" -Dave Keenan