Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: ip address calculations

by tachyon (Chancellor)
on May 06, 2002 at 11:57 UTC ( #164289=note: print w/replies, xml ) Need Help??


in reply to ip address calculations

Socket the inet() functions and pack and unpack can do the first job. This takes under a second to run:

use Socket; my $begin = "172.16.0.1"; my $end = "172.17.3.10"; my $ip = unpack N, inet_aton($begin); my $ip_end = unpack N, inet_aton($end); while ( $ip <= $ip_end ) { print inet_ntoa(pack N,$ip), "\n"; $ip++; }

NetAddr::IP does the rest.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: ip address calculations
by arc_of_descent (Hermit) on May 06, 2002 at 13:30 UTC

    Yes! Very Interesting
    Thanx

    But i want to neglect ip addresses which are network or broadcast addresses.
    The above code prints out 172.16.2.0, 172.16.2.255, etc.
    I really want this functionality for users who are supposed
    to allocate ip addresses from a pool which they have defined
    using start and end ip addresses.
    I guess i'll have to put additional code to neglect
    the network and broadcast addresses.

    Thanx a lot!

    --
    arc_of_descent

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2019-10-15 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?