programming-examples/perl/Network/Translating IP addresses into hostnames.pl
2019-11-15 12:59:38 +01:00

13 lines
251 B
Perl

#!/usr/bin/perl
use Socket;
my $ADDR_PAT = /^\d+\.\d+\.\d+\.\d+$/;
while (<>) {
chomp;
die "$_: Not a valid address" unless /$ADDR_PAT/o;
my $name = gethostbyaddr(inet_aton($_),AF_INET);
$name ||= '?';
print "$_ => $name\n";
}