in reply to Re^2: IP Iteratorin thread IP Iterator
Nope. All you need is the following:
sub ip_fr_dotted { unpack 'N', pack 'C4', split /\./, $_[0] } sub ip_to_dotted { join '.', unpack 'C4', pack 'N', $_[0] } my $start = ip_fr_dotted('10.0.0.0'); my $end = ip_fr_dotted('10.0.0.255'); for (my $ip=$start; $ip<=$end; $ip++) { print(ip_to_dotted($ip), "\n"); } [download]
I didn't use for my $ip ($start..$end) since it doesn't work for IP addresses ≥ 128.0.0.0 on a 32-bit system.
10.0.1.252 10.0.1.253 10.0.1.254 10.0.1.255 10.0.2.0 10.0.2.1 10.0.2.2 10.0.2.3 10.0.2.4 10.0.2.5 [download]
sub ip_fr_dotted { unpack 'N', pack 'C4', split /\./, $_[0] } sub ip_to_dotted { join '.', unpack 'C4', pack 'N', $_[0] } my $start = ip_fr_dotted('10.0.0.200'); my $end = ip_fr_dotted('10.0.2.23'); for (my $ip=$start; $ip<=$end; $ip++) { print(ip_to_dotted($ip), "\n"); } [download]