It was probably just a typo, but the range of IP addresses in 10.1.2.0/23 is actually 10.1.2.0 to 10.1.3.255, or 512 addresses. In addition to excluding the subnet and broadcast addresses (which one could argue was correct), the beginning third octet was incorrectly listed as 1 instead of 2.
I agree wholeheartedly that the RegExp/string approach is needlessly complex when compared to an elegant numeric solution -- especially if we can't assume (and what happens when we assume? xD ) that we're only working with 24-bit subnet masks. I've supported this opinion (at length) in another post, so I won't re-hash it here. Cheers, -Brian _________________________ Brian H. Oak CISSP CISA Acorn Networks & Security <http://acornnetsec.com/> -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bullock, Howard A. Sent: Thursday, November 10, 2005 11:22 To: Pierce, Glen E; Jason Gerfen Cc: [email protected] Subject: RE: network matching -> regexp [top post] How would you handle the following subnets using this approach? Subnet 10.1.2.0/23 The IP range is from 10.1.1.1 to 10.1.3.254 Then given Subnet 10.1.4.0/26 The IP range is from 10.1.4.1 to 10.1.4.62 I posted what I believe to be a more generic lower maintenance approach in a separate post. -------------------------------- example usage: if( chk_ip( $_ ) == 0 ) { // valid IPv4 address } elif { // no a valid IPv4 address } valid 192.168.2.255 not valid 256.256.256.256 sub chk_ip( $ip ) { my $ip = shift( @ARGV ); if( $ip =~ /^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/ ) { for( $i = 1; $i <= 3; $i++ ) { if( !( substr( $ip, 0, strpos( $ip, "." ) ) >= "0" && substr( $ip, 0, strpos( $ip, "." ) ) <= "255" ) ) { return 1; } $ip = substr( $ip, index( $ip, "." ) + 1 ); } if( !( $ip >= "0" && $ip <= "255" ) ) { return 1; } } else { return 1; } return 0; } _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
