|
Here is a short snippet of code which shows you
how to validate an IP address using
Regexp::Common.
#!/usr/bin/perl -w
use strict;
use Regexp::Common;
while (<DATA>) {
print '-' x 30, "\n";
chomp;
foreach my $i (qw( dec hex oct bin)) {
if(/(?i)$RE{net}{IPv4}{$i}{-keep}/) {
print "$_ matches $i, $1\n";
}
}
}
__DATA__
255.255.255.255
255.255.255.0
0.0.0.0
127.0.0.1
192.168.0.1
192.168.0.254
11.22.33.44
aa.bb.cc.dd
c7.ae.04.ad
199.174.4.173
C7.AE.04.AD
|