in reply to RFC: CPAN module Net::IP::Correct

I'm confused. There's nothing "incorrect" about 192.168.1.0 - 192.168.1.5.

Then, also, how is this different from Net::IP's ip_range_to_prefix?

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: RFC: CPAN module Net::IP::Correct
by arc_of_descent (Hermit) on Jun 29, 2005 at 14:35 UTC

    I guess I should be using the word block instead of range. 192.168.1.0 - 192.168.1.5 is fundamentally an incorrect IP block which if used in many utilities (iptables for example; on Linux), would raise an error (or not, depending on the utility). But the fact remains, that it is an incorrect IP block.

    The aim of this module is to take an IP range, and split the range into correct IP blocks starting from the largest possible, to the smallest block possible.

    So if we have a range like 192.168.1.0 - 192.168.2.130 for example, this module would split this range into the following valid IP blocks:

    • 192.168.1.0/255.255.255.0 (192.168.1.0 - 192.168.1.255)
    • 192.168.2.0/255.255.255.128 (192.168.2.0 - 192.168.2.127)
    • 192.168.2.128/255.255.255.254 (192.168.2.128 - 192.168.2.129)
    • 192.168.2.130/255.255.255.255 (192.168.2.130)
    I hope I'm clear enough :-)
      Net::IP Already does this: Quick-N-Dirty copy of a Oneliner I got aliased:
      use Net::IP; $i=new Net::IP("$ARGV[0]-$ARGV[1]"); @l=$i->find_prefixes(); foreach(@l){ ($i,$m)=split("/"); $i=new Net::IP($i); print$i->short()."/$m\n"; }
      Pass it: 192.168.1.0 192.168.2.130
      Output:
      192.168.1.0/24 192.168.2.0/25 192.168.2.128/31 192.168.2.130/32
      Yes it requires a 'bit' of coding, and IMO would be better suited to go into Net::IP instead of a new module.

      BIG HUGE DISCLAIMER (for Dio): THIS CODE SUCKS AND PROBABLY WILL BREAK

        Thats nice!

        find_prefixes from Net::IP works great and does get the work done. I don't think we require this module. Thanks!