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 \s-1IP\s0 addresses against many \s-1CIDR\s0 subnets and calculates \s-1IP\s0 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

my $subnets = Net::Subnets->new;

Creates an "Net::Subnets" object. $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. my $match = $subnets->check(\$address);

The C<check> method lets you check an IP address against the previously prepared subnets. my ($lowest, $highest) = $subnets->range(\$subnet)

The C<range> method lets you calculate the IP address range of a subnet. 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 ([email protected]), Juergen Peters ([email protected])

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.