View on
MetaCPAN
Paul W Bennett > Net-IPAddress-Util > Net::IPAddress::Util::Range

Download:
Net-IPAddress-Util-3.031.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

Net::IPAddress::Util::Range - Representation of a range of IP addresses

VERSION ^

Version 3.031

SYNOPSIS ^

  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 });

DESCRIPTION ^

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.

CLASS METHODS ^

new

The constructor. Takes a hashref with:

lower and 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.

ip and 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.

ip and 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.

OBJECT METHODS ^

'""'

as_string

Objects stringify to a representation of their range.

as_cidr

Stringification for CIDR-style strings.

as_netmask

Stringification for Netmask-style strings.

outer_bounds

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.

inner_bounds

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.

tight

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.

loose

Returns a blessed object (of this class) representing the range returned by outer_bounds().

lower

upper

Get the lower or upper bounds of this range.

syntax highlighting: