Net::CIDR::Compare - Find intersections across multiple lists of CIDR ranges, fast.
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
}
$collection->remove_list($second_list);
$collection->process_intersection(expand_cidr => 8);
while (my $cidr_range = $collection->get_next_intersection_range()) {
print "$cidr_range\n"; # prints 10.10.0.0/16
}
This module accepts various formats of IPv4 ranges, converts non-CIDR
ranges to CIDR, and produces the intersection of CIDR ranges across
all the lists in the collection.
Net::CIDR::Compare was designed to handle large IPv4 lists and compute
the intersection of these lists in a memory-efficient and speedy way.
The intersection code is C code and Perl-wrapped using XS. You will
need a C compiler to install this code.
Although the main driver for this module's creation is to find the
intersection across several lists, this module can also be used with just
a single list to convert non-CIDR range formats to CIDR and merge ranges
quickly.
Net::CIDR::Compare also requires Net::CIDR and Net::Netmask for some
of the range format conversions (e.g. converting 10.0.0.* to 10.0.0.0/24).
Net::CIDR::Compare objects are created with one optional parameter,
print_errors. Errors are always stored in $collection->{error} (from
above example). If print_errors is set (default yes) then errors
are also printed to STDERR.
$collection = Net::CIDR::Compare->new(print_errors => 1)
Sections of this code were obtained from a C program called cidr-convert
which can be found on numerous sites. The sourcecode claimed to be of
"the public domain." This code is also part of the public domain.
Please send feedback to grjones@gmail.com.