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

Re: Increment of ip address

by monarch (Priest)
on Jun 17, 2005 at 00:54 UTC ( #467517=note: print w/ replies, xml ) Need Help??


in reply to Increment of ip address

In thread perl ipcalc oneliners I posted some quick math subroutines you can use for converting your IP address into a number and back for arithmetic purposes without relying on any other module.

Try using:

sub addrtoint { return( unpack( "N", pack( "C4", split( /[.]/,$_[0] ) ) ) ) }; sub inttoaddr { return( join( ".", unpack( "C4", pack( "N", $_[0] ) ) ) ) }; my $ipinc = addrtoint( '1.2.3.4' ); $ipinc++; print( inttoaddr( $ipinc ) . "\n" );


Comment on Re: Increment of ip address
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-11-23 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (131 votes), past polls