Net::IPAddress::Util::Range - Representation of a range of IP addresses
Version 4.004
use Net::IPAddress::Util::Range; my $x = '192.168.0.3'; my $y = '192.168.0.123'; my $range = Net::IPAddress::Util::Range->new({ lower => $x, upper => $y }); print "$range\n"; # (192.168.0.3 .. 192.168.0.123) for (@{$range->tight()}) { print "$_\n"; } my $w = '192.168.0.0/24'; my $range = Net::IPAddress::Util::Range->new({ ip => $w }); my $v = '192.168.0.0'; my $range = Net::IPAddress::Util::Range->new({ ip => $v, cidr => 24 }); my $z = '255.255.255.0'; my $range = Net::IPAddress::Util::Range->new({ ip => $v, netmask => $z });
Sometimes when dealing with IP Addresses, it can be nice to talk about contiguous ranges of them as whole collections of addresses without worrying that the contiguous range is exactly a CIDR-compatible range.
This is what Net::IPAdress::Util::Range is for. Objects of this class act as type-checked pairs of lower and upper bounds of a range of IP Addresses.
The constructor. Takes a hashref with:
lower
upper
In this case, construction is straightforward. The two values must be either Net::IPAddress::Util objects, or something that can be used to construct one.
ip
If the ip is a Net::IPAddress::Util object (or something that can be used to construct one), then you get a Range consisting of a single IP. This may seem redundant, but allows Net::IPAddress::Util::Collection to do magic.
Also, as a convenience, CIDR strings (of the form "N.N.N.N/X", etc) may be passed in, and you'll get back a Range representing that whole CIDR.
cidr
Pass in an IP and a numeric CIDR (which MUST be valid for the version (4 or 6) of the IP), and you'll get back a Range representing that whole CIDR.
netmask
Pass in two IPs, of the same version, and they'll be treated exacatly as the argument names suggest. The netmask argument MUST (in binary) start with zero or more ones, followed by enough zeroes to pad out to the correct number of bits (either 32 or 128 for IPv4 or IPv6 respectively). The ip argument MUST have the same number of right-hand zeroes as the netmask argument.
Objects stringify to a representation of their range.
Stringification for CIDR-style strings.
Stringification for Netmask-style strings.
Return the bounds of the smallest subnet capable of completely containing the addresses in this range. Note that this is not automatically the same thing as "the subnet that matches this range", as a range may or may not be aligned to legal subnet boundaries.
Return the bounds of the largest subnet capable of being completely contained by the addresses in this range. Note that this is not automatically the same thing as "the subnet that matches this range", as a range may or may not be aligned to legal subnet boundaries.
Returns a collection of subnets that (between them) exactly match the addresses in this range. The returned object is a Net::IPAddress::Util::Collection, which can be treated as an array reference of Net::IPAddress::Util::Range objects.
Returns a blessed object (of this class) representing the range returned by outer_bounds().
Get the lower or upper bounds of this range.
To install Net::IPAddress::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::IPAddress::Util
CPAN shell
perl -MCPAN -e shell install Net::IPAddress::Util
For more information on module installation, please visit the detailed CPAN module installation guide.