in reply to Checking IP's with an IP/mask

You mean to find out if the arbitrary IP is in the range given by the CIDR notation (such as is 192.168.1.2 in the range 10.0.2.0/24)?

*sigh* I wish I had found this post earlier today, when I wrote my own function to do this (which someone else has probably already come up with, and easier, probably):

sub inblock { my($block, $cidr, $target) = @_; my $result = 1, $machinebits = (32 - $cidr); my $lip1 = unpack("N", pack("c4", split(/\D/, $block, 4))); my $lip2 = unpack("N", pack("c4", split(/\D/, $target, 4))); $result = 0 if (($lip1 >> $machinebits) != ($lip2 >> $machinebits)); return($result); }

Replies are listed 'Best First'.
Re: Re: Checking IP's with an IP/mask
by strredwolf (Chaplain) on Dec 11, 2001 at 11:20 UTC
    Intresting, but I'm now using Net::Netmask for that now. Bloodtyger's happy for it.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";