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
In reply to Re: Iterating through all IP addresses in a CIDR
by BrowserUk
in thread Iterating through all IP addresses in a CIDR
by grinder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |