Here is my own code (derived from Re: Checking IP's with an IP/mask) to generate the list, without using Net::Netmask. It also seems to work for supernetted blocks through at least a /8 (just finished that test-16,777,216 addresses and code feels fine). Included is my test code for a block (in this case, 192.168.1.32/28). The code also makes allowances for if you want to generate the list with/without the network, gateway, and/or broadcast addresses included.
(Might could use some clean-up by way of making sure that $nonetwork, $nogateway, and $nobroadcast are only set either 0 or 1.)
#!/usr/bin/perl -w --
use strict;
#
# Set to 1 to remove from generated list, 0 to leave in
#
my $nonetwork = 1;
my $nogateway = 1;
my $nobroadcast = 1;
my $block = '192.168.1.32';
my $cidr = 28;
my $machines = 2**(32 - $cidr);
my $lip = unpack("N", pack("C4", split(/\D/, $block, 4)));
#
# Assumes gateway is at beginning, not end, of block
#
for (my $i = ($nonetwork + $nogateway);
$i < ($machines - $nobroadcast);
$i++)
my $res = $lip + $i;
print(join('.', unpack("C4", pack("N", $res))), "\n");
}
Comments? Questions? Hope this helps.
Update: Noted in several of the posts afterwards that the input format was discussed. In my code above, I believe significate modification would likely be required to use netmask rather than CIDR notation. |