Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Splitting IP ranges depending on overlap conditions

by eXile (Priest)
on Apr 14, 2006 at 15:26 UTC ( #543373=note: print w/replies, xml ) Need Help??

in reply to Splitting IP ranges depending on overlap conditions

I'm not aware of a CPAN module that can do this.

You could convert your dotted-quad IP-addresses to integers, so you can do some simple math with them:

if ( $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ ) { $number = $1 >> 24 + $2 >> 16 + $3 >> 8 + $4 }

Replies are listed 'Best First'.
Re^2: Splitting IP ranges depending on overlap conditions
by fishbot_v2 (Chaplain) on Apr 14, 2006 at 17:49 UTC

    TMTOWTDI, and I normally do this sort of thing:

    use strict; use warnings; use Socket qw{ inet_aton inet_ntoa }; sub ip_to_num { unpack( 'N', inet_aton( shift )); } sub ip_to_str { inet_ntoa( pack( 'N', shift )); } sub ip_plus { ip_to_str( ip_to_num( $_[0] ) + $_[1] ); } sub ip_minus { ip_plus( $_[0], -$_[1] ); } my $dotted_quad = ''; print ip_plus( $dotted_quad, 290 ), "\n"; print ip_minus( $dotted_quad, 3 ), "\n"; __END__

    In the OPs case, he only needs to add 1 and subtract 1. Again, all of this craps out on IPv6. I suspect that isn't a concern yet.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://543373]
[oiskuu]: .oO( Lots of poorly tuned pianos await in thezip's hell. )
[thezip]: Apparently I have already reached my destination...
[erix]: pianola's :P
[oiskuu]: Prepare your piano with tuna and your cat will show you some love.
thezip has a sudden compusion to dance the tango...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-11-17 19:30 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.