Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How many addresses between two IPs?

by gellyfish (Monsignor)
on Jan 28, 2005 at 12:00 UTC ( #425913=note: print w/replies, xml ) Need Help??


in reply to How many addresses between two IPs?

Cool. I haven't had a look at NetAddr::IP but I had to some similar calculation in one of the NMS programs where we don't want to use non-core modules (in this case to determine if an IP was in a specified network.) In case one is in a similar position of needing to do this calculation and not able to install the module, the code can boil down to:

use Socket; sub add_number_to_ip { my ($ip,$number ) = @_; my $ip_i = ip_to_int($ip); $ip_i += $number; return inet_ntoa(pack('N', $ip_i)); } + sub ip_to_int { my ( $ip ) = @_; my $ip_n = inet_aton($ip); my $ip_i = unpack('N', $ip_n); return $ip_i }
but, yes, you are probably better off using the module if you can.

/J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://425913]
help
Chatterbox?
[holli]: i didnt pay attention when i bought it. it's one of those where backspace is just one unit wide
[holli]: in what way improved?
[ambrus]: I may have ruined my good keyboard on Friday by spilling tea in it. I hope it's just temporarily malfunctioning until it dries out, but I fear it might be permanently damaged.
[holli]: did you soak the controller boardlet?
[Eily]: could be worse, you might have ruined your tea with the content of the keyboard
[holli]: if you didnt you should be fine
LanX .oO( holli needs standards which are standardized!!)
[holli]: do i?
[holli]: oh for the keyboard

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-11-21 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (302 votes). Check out past polls.

    Notices?