http://qs1969.pair.com?node_id=513815


in reply to Script to input IP Address and Subnet Bits (10.3.2.0/28)

Hello. I only have a suggention on the IP matching part. I've always found myself using the below extra-large regexp, courtesy of Mastering Regular Expressions.
my @ips = qw( 127.0.0.1 0.0.0.0 256.0.0.1 123.555.333.222666 ); foreach my $ip (@ips) { my $f = undef; if($ip =~ m/^(?!0+\.0+\.0+\.0) ([01]?\d\d?|2[0-4]\d|25[0-5]) \.([01]?\d\d?|2[0-4]\d|25[0-5]) \.([01]?\d\d?|2[0-4]\d|25[0-5]) \.([01]?\d\d?|2[0-4]\d|25[0-5])$/x ) { $f =1; } print 'Is', $f ? "" : 'n\'t', " valid and/or usable IP: $ip \n" }
When run produces:
Is valid and/or usable IP: 127.0.0.1 Isn't valid and/or usable IP: 0.0.0.0 Isn't valid and/or usable IP: 256.0.0.1 Isn't valid and/or usable IP: 123.555.333.222666
Update: changed code to better illustrate its usefulness.