Net::Subnets(3pm) User Contributed Perl Documentation Net::Subnets(3pm)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
";
}
else {
$results .= "$address: not found
";
}
}
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
";
}
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.
perl v5.10.1 2009-12-18 Net::Subnets(3pm)
Check Out this Related Man Page
IPSEC_SAMEADDR(3) Library Functions Manual IPSEC_SAMEADDR(3)NAME
ipsec_sameaddr, ipsec_addrcmp, ipsec_samesubnet, ipsec_addrinsubnet, ipsec_subnetinsubnet, ipsec_subnetishost, ipsec_samesaid,
ipsec_sameaddrtype, ipsec_samesubnettype - do comparisons for addresses, subnets, SA IDs and address families
SYNOPSIS
#include <freeswan.h>
int sameaddr(const ip_address *a, const ip_address *b);
int addrcmp(const ip_address *a, const ip_address *b);
int samesubnet(const ip_subnet *a, const ip_subnet *b);
int addrinsubnet(const ip_address *a, const ip_subnet *s);
int subnetinsubnet(const ip_subnet *a, const ip_subnet *b);
int subnetishost(const ip_subnet *s);
int samesaid(const ip_said *a, const ip_said *b);
int sameaddrtype(const ip_address *a, const ip_address *b);
int samesubnettype(const ip_subnet *a, const ip_subnet *b);
DESCRIPTION
These functions do various comparisons and tests on the ip_address type and ip_subnet types.
Sameaddr returns non-zero if addresses a and b are identical, and 0 otherwise. Addresses of different families are never identical.
Addrcmp returns -1, 0, or 1 respectively if address a is less than, equal to, or greater than b. If they are not of the same address fam-
ily, they are never equal; the ordering reported in this case is arbitrary (and probably not useful) but consistent.
Samesubnet returns non-zero if subnets a and b are identical, and 0 otherwise. Subnets of different address families are never identical.
Addrinsubnet returns non-zero if address a is within subnet s and 0 otherwise. An address is never within a subnet of a different address
family.
Subnetinsubnet returns non-zero if subnet a is a subset of subnet b and 0 otherwise. A subnet is deemed to be a subset of itself. A sub-
net is never a subset of another subnet if their address families differ.
Subnetishost returns non-zero if subnet s is in fact only a single host, and 0 otherwise.
Samesaid returns non-zero if SA IDs a and b are identical, and 0 otherwise.
Sameaddrtype returns non-zero if addresses a and b are of the same address family, and 0 otherwise.
Samesubnettype returns non-zero if subnets a and b are of the same address family, and 0 otherwise.
SEE ALSO inet(3), ipsec_initaddr(3)HISTORY
Written for the FreeS/WAN project by Henry Spencer.
28 Nov 2000 IPSEC_SAMEADDR(3)