Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: IP list generation

by merlyn (Sage)
on Feb 16, 2001 at 22:40 UTC ( [id://58925]=note: print w/replies, xml ) Need Help??


in reply to IP list generation

Perhaps you'd get somewhere by mapping them to a proper enumeration. Maybe this will help:
my @range = map { unpack "N", pack "C4", split /\./ } qw(10.0.70.1 10. +1.50.20); print "@range\n"; # the numbers themselves print $range[1]-$range[0]+1, "\n"; # how many addresses for ($range[0]..$range[1]) { print join(".", unpack "C4", pack "N", $_), "\n"; }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: IP list generation
by ryan (Pilgrim) on Feb 16, 2001 at 23:00 UTC
    Thank you so much, amazing :)

    Being a possessor of only basic Perl knowledge I am still wrapping my intellect around this code, it's getting clearer now.

    It's so depressing comparing the number of lines of code I used to do it :P

    Thanks again

Re: Re: IP list generation
by $code or die (Deacon) on Apr 28, 2001 at 21:39 UTC
    Great node. I had to modify the "for" loop for large IP addresses, e.g. starting with 128 and above.

    I now use something like this:
    my @range = map { unpack "N", pack "C4", split /\./ } ($ARGV[0], $ARGV +[1]); print "@range\n"; # the numbers themselves print $range[1]-$range[0]+1, "\n"; # how many addresses for (my $i = $range[0]; $i <= $range[1]; $i++) { print join(".", unpack "C4", pack "N", $i), "\n"; }
    I was getting this error:
    Range iterator outside integer range


    $ perldoc perldoc

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://58925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found