in reply to Increment of ip address
You can add or subtract any amount to an IP address this way. Carry-over into the next "quad" is automatic... but that may not be what you want. :-)use Socket; sub add_to_ip($$) { my( $ip, $add ) = @_; inet_ntoa pack( 'N', unpack('N',inet_aton $ip) + $add ) }
$j = add_to_ip( $i, 1 ); # simple increment $j = add_to_ip( $i, -1 ); # simple decrement $j = add_to_ip( $i, 300 ); # addition carries over into the next-to-la +st quad.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Increment of ip address
by mosh (Scribe) on Jun 16, 2005 at 18:13 UTC | |
by northwind (Hermit) on Jun 16, 2005 at 18:41 UTC |