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

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:

I hope I'm clear enough :-)
  • Comment on Re^2: RFC: CPAN module Net::IP::Correct

Replies are listed 'Best First'.
Re^3: RFC: CPAN module Net::IP::Correct
by OverlordQ (Hermit) on Jun 30, 2005 at 04:32 UTC
    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!

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

        Excellent -- not having to write any code is always a good result.

        But ... since you found this feature of Net::IP non-obviously, I was wondering whether other people might too. Perhaps you could submit a doc patch (with an example) to the Net::IP people, so that anybody wanting to do what you're doing can easily see how it's done?

        Smylers