I have two lists. One list with networks (e.g. 10.0.0.0/8 etc.) and a second list with subnets (e.g. 10.10.1.0/24 or /27 /28 etc.). I would like to figure out, which of the subnets fit in the first 'container'-network (using perl).
Any ideas?
I have two lists. One list with networks (e.g. 10.0.0.0/8 etc.) and a second list with subnets (e.g. 10.10.1.0/24 or /27 /28 etc.). I would like to figure out, which of the subnets fit in the first 'container'-network (using perl).
Any ideas?
The Net::CIDR::Compare package on CPAN is probably what you are looking for. From the example code:
use Net::CIDR::Compare;
my $collection = Net::CIDR::Compare->new(print_errors => 1);
my $first_list = $collection->new_list();
$collection->add_range($first_list, "10.10.0.0/16", 1);
my $second_list = $collection->new_list();
$collection->add_range($second_list, "10.10.200.0/24", 1);
$collection->process_intersection(expand_cidr => 8);
while (my $cidr_range = $collection->get_next_intersection_range()) {
print "$cidr_range\n"; # prints 10.10.200.0/24
}
Check NetAddr::IP
use NetAddr::IP;
my $range1 = NetAddr::IP->new("10.0.0.0/8");
my $range2 = NetAddr::IP->new("10.10.1.0/24");
print "range1 contains range2\n" if $range1->contains($range2);