Far too complex!
#! /usr/bin/perl -w use strict; use Socket; for( @ARGV ) { if( my $host = gethostbyaddr( inet_aton($_), AF_INET )) { print "$_ is $host\n"; } else { print "$_ NXDOMAIN\n"; } }
Works on my machine :)
Note that this will return one record. If you are doing funky things with multiple A or PTR records it might miss the information you're interested in. In which case the Net::DNS module will let you iterate through the RR set. Otherwise it's overkill.
In reply to Re:x2 hostname from ip (use gethostbyaddr)
by grinder
in thread hostname from ip
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |