1) $ perl -le' use Socket; my @tests = ( "127.1", "127.0.0.3", "10.11.12.13", "300.1.2.2" ); for my $test ( @tests ) { print "$test is ", inet_aton( $test ) ? "" : "NOT ", "a valid IP a +ddress."; } ' 127.1 is a valid IP address. 127.0.0.3 is a valid IP address. 10.11.12.13 is a valid IP address. 300.1.2.2 is NOT a valid IP address. 2) $ perl -le' use Socket; my @tests = ( "255.243.0.0", "255.240.0.0", "255.255.255.0", "255.255. +248.0" ); for my $test ( @tests ) { print "$test is ", unpack( "B*", inet_aton( $test ) ) =~ /^1+0+$/ +? "" : "NOT ", "a subnet mask."; } ' 255.243.0.0 is NOT a subnet mask. 255.240.0.0 is a subnet mask. 255.255.255.0 is a subnet mask. 255.255.248.0 is a subnet mask.
In reply to Re: Parsing IPv4 Addresses and distinguishing Masks
by Anonymous Monk
in thread Parsing IPv4 Addresses and distinguishing Masks
by ewhitt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |