Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Iterating through all IP addresses in a CIDR

by BrowserUk (Patriarch)
on Nov 04, 2003 at 16:22 UTC ( [id://304461]=note: print w/replies, xml ) Need Help??


in reply to Iterating through all IP addresses in a CIDR

Only deals with IPv4.. but extending it wouldn't be hard.

#! perl -slw use strict; our $M ||= 30; our $IP ||= '1.2.3.4'; sub bin2dd{ join '.', unpack 'C4', pack 'N', $_[0] } sub dd2bin{ unpack 'N', pack'C4', split'\.', $_[0] } sub CIDRList{ my $iter = 0xffffffff >> $_[0]; my $mask = ~$iter; my $lo = dd2bin( $_[1] ) & $mask; map{ bin2dd $lo++ } 0 .. $iter; } print for CIDRList $M, $IP; __END__ P:\test>CIDR -M=28 -IP=64.96.128.0 64.96.128.0 64.96.128.1 64.96.128.2 64.96.128.3 64.96.128.4 64.96.128.5 64.96.128.6 64.96.128.7 64.96.128.8 64.96.128.9 64.96.128.10 64.96.128.11 64.96.128.12 64.96.128.13 64.96.128.14 64.96.128.15

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found