[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

Reply via email to