Provided by: libnet-subnets-perl_1.0-1_all
NAME
Net::Subnets - Computing Subnets In Large Scale Networks
SYNOPSIS
use Net::Subnets; my $sn = Net::Subnets->new; $sn->subnets(\@subnets); if (my $subnetref = $sn->check(\$address)) { ... } my ($lowipref, highipref) = $sn->range(\$subnet); my $listref = $sn->list(\($lowipref, $highipref));
DESCRIPTION
Very fast matches large lists of IP addresses against many CIDR subnets and calculates IP address ranges. This is a simple and efficient example for subnet matching: use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.0/24); my @addresses = qw/10.0.0.1 10.0.1.2 10.0.3.1/; my $sn = Net::Subnets->new; $sn->subnets(\@subnets); my $results; foreach my $address (@addresses) { if (my $subnetref = $sn->check(\$address)) { $results .= "$address: $$subnetref\n"; } else { $results .= "$address: not found\n"; } } print($results); This is a simple example for range calculation: use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.0/24); my $sn = Net::Subnets->new; my $results; foreach my $subnet (@subnets) { my ($lowipref, $highipref) = $sn->range(\$subnet); $results .= "$subnet: $$lowipref - $$highipref\n"; } print( $results ); This is a simple example for list generation: use Net::Subnets; my $lowip = '192.168.0.1'; my $highip = '192.168.0.100'; my $sn = Net::Subnets->new; my $listref = $sn->list(\($lowip, $highip)); foreach my $address (@$listref) { # do something cool }
METHODS
"new" my $subnets = Net::Subnets->new; Creates an "Net::Subnets" object. "subnets" $subnets->subnets([qw(10.0.0.0/24 10.0.1.0/24)]); The C<subnets> method lets you prepare a list of CIDR subnets. "check" my $match = $subnets->check(\$address); The C<check> method lets you check an IP address against the previously prepared subnets. "range" my ($lowest, $highest) = $subnets->range(\$subnet) The C<range> method lets you calculate the IP address range of a subnet. "list" my $list = $subnets->list(\$lowest, $highest); The C<list> method lets you calculate a list containing all IP addresses in a given range.
AUTHOR
Sebastian Riedel (sri@cpan.org), Juergen Peters (juergen.peters@taulmarill.de)
COPYRIGHT AND LICENSE
Copyright (C) 2003-2009, Sebastian Riedel. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.