Noosrep Noosrep - 6 months ago 21
Perl Question

Find all IPs from subnet in perl

I have an IP with subnetmask and want to create a table in which every row is an IP.

Kind of like this:

IP | MAC | Alive | ... | yes | ... | no | ... | yes

For a range with subnet /24, this is easy because I can generate a for loop from 0 to 254 but I'm having trouble with generating the table with a /21 subnet. Is there a way to find in perl what the minimum host, the maximum host and everything in between is?

I have checked the
and the
module but don't seem a solution for my problem. However, I'm a perl newbie so it could be that I overlooked it.

found how to find first and last address:

my $range = "IP/subnet" ;
my $ip = new Net::IP ($range) || die;
print $ip->ip (), "\n";
print $ip->last_ip (), "\n";

Now I need to find the IPs in between

Mat Mat

The docs for Net::IP has an example for how to do this in the looping section.


use Net::IP;

my $ip = new Net::IP("");
do {
  print $ip->ip(), "\n";
} while (++$ip);