Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Just another Perl shrine
 
PerlMonks

Re: RFC: CPAN module Net::IP::Correct

by merlyn (Sage)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Jun 29, 2005 at 12:00 UTC ( #470976=note: print w/ replies, xml ) Need Help??

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.


Comment on Re: RFC: CPAN module Net::IP::Correct
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!

Login:
Password
remember me
What's my password?
Create A New User

Node Status?
node history
Node Type: note [id://470976]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (15)
GrandFather
borisz
jdporter
atcroft
duff
herveus
MidLifeXis
lidden
muba
ssandv
djp
james2vegas
AndyZaft
Neighbour
BourneID
As of 2010-09-06 03:26 GMT
Sections?
Seekers of Perl Wisdom
Cool Uses for Perl
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Perl News
See About the sections of PerlMonks
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

My favourite poll on PerlMonks is ...

Your first Perl Book - the first one ever
Average number of caffeinated beverages per work day - the poll with the highest participation
My Thoughts on the New Voting/Experience System - the poll with the fewest votes cast
When I grow up, I want to be: - one of the polls with the fewest options
Perl 6 will primarily be: - the first one on Perl6
When I see a poll - one of the many polls about polls
this poll ;-)
yet to come
none - I hate polls. Bah.
some other

Results (95 votes), past polls