in reply to Matching Sequential IP Addresses

Thank you all for the great responses. I actually found a fairly simple way (although not using grep or map) to do what I needed to do:
my %hashSeg; for my $ip (sort keys %hashIPs) { if ($ip =~ /(\d{1,3}\.\d{1,3}\.\d{1,3})\.\d{1,3}/){ my $seg = $1; $hashSeg{$seg}++; } } for my $seg (keys %hashSeg){ if ($hashSeg{$seg} ne '255'){ print "$seg is not a full \/24\n"; } else { print "$seg is a full \/24\n"; } }
Thanks,
Dru

Perl, the Leatherman of Programming languages. - qazwart

Replies are listed 'Best First'.
Re^2: Matching Sequential IP Addresses
by ikegami (Patriarch) on Apr 07, 2008 at 03:47 UTC
    ne '255' should be != 255. Shouldn't that be 256 anyway? (0..255 is 256 numbers.)

      A standard Class C network consists of 256 addresses (0 to 255 inclusive), of which one is the network address (.0) and the other is the network broadcast address (.255). Although there are exceptions you can't really use .0 or .255 so there are really only 254 useable addresses.

      As a policy I would use < 255 myself as would deal with edge cases where ips are repeated more than once. I have some trial software that amuses me with it's message that it expires in -119 days. Clearly they coded an == rather than a < 0.

      To make this stype of solution reliable you need a pre-filter to exclude duplicate ips from the list as our logic requires that they must be unique. In this case the OP is using that so all will be well.