programming-examples/perl/Network/Using regular expresion to validate an IP address.pl
2019-11-15 12:59:38 +01:00

12 lines
249 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";
}