in reply to Re: Checking IP's with an IP/mask
in thread Checking IP's with an IP/mask

I don't know much about network addresses, but isn't something like this sufficient?
use Socket; sub IsInRange { my ($addr,$base) = @_; my $bits; ($base, $bits) = split /\//, $base; return ( (unpack("N", inet_aton($base)) >> (32 - $bits)) == (unpack ("N", inet_aton($addr)) >> (32 - $bits)) ); }

Replies are listed 'Best First'.
Re^3: Checking IP's with an IP/mask
by tadman (Prior) on Apr 24, 2001 at 18:49 UTC
    This should work too, and is probably better because of simplicity.

    For those wondering, what this code effectively does is compare the network numbers of the $addr and the $base specification by shifting the host bits off the end (with the >> operator). What I was doing was building a range specification, which given the task, is really overkill.

    Well put.