NAME
Net::Silk::Range - SiLK IP and proto/port range class
SYNOPSIS
use Net::Silk::Range;
my $r = Net::Silk::Range->new('1.1.1.1' => '1.255.255.255');
# or could have used "1.1.1.1-1.255.255.255"
$r->contains("1.1.1.2"); # true
print "$r\n"; # 1.1.1.1-1.255.255.255
print join(' ', $r->first, $r->last), "\n"; # 1.1.1.1 1.255.255.255
print join(' ', @$r, "\n"; # 1.1.1.1 1.255.255.255
my $size = $r->cardinality; # 16711423
use Net::Silk::IPSet;
my $s = Net::Silk::IPSet->load("my.set");
my $iter = $s->iter_ranges;
while (my $r = $iter->()) {
... # $r is a Net::Silk::Range
}
use Net::Silk::Pmap;
my $s = Net::Silk::Pmap->load("my.pmap");
my $iter = $s->iter_ranges;
while (my($k, $v) = each %$s) {
... # $k is a Net::Silk::Range
}
DESCRIPTION
Net::Silk::Range
is a lightweight wrapper around an IP block specified by a first and last value. It is returned by iterators in Net::Silk::IPSet, Net::Silk::Pmap, and Net::Silk::IPWildcard.
METHODS
- new($first, $last)
- new([$first, $last])
- new($string)
-
Returns a new
Net::Silk::Range
object represented by the given low and high values. The two values can be provided either as separate arguments, an array ref, or a string representation. The values are Net::Silk::IPAddr or Net::Silk::ProtoPort objects or their string representations. - first()
-
Return the first value in the range. This can alternately be accessed via
$r->[0]
. - last()
-
Return the last value in the range. This can alternately be accessed via
$r->[1]
. - carinality()
-
Return the number of elements in this range.
- contains($item)
-
Return whether or not the given item is contained in this range.
- as_cidr()
-
Returns an array or array ref (depending on context) of Net::Silk::CIDR blocks are covered by this range.
- as_str()
-
Return a string in the form of
"first-last"
. This method gets invoked automatically when the range is used in string context. - iter()
-
Return a sub ref that iterates over all elements of this range. Treating the range like a filehandle
<$r>
yields the same results.
OVERLOADED OPERATORS
The following operators are overloaded:
<> ""
eq ==
ne !=
cmp <=>
SEE ALSO
Net::Silk, Net::Silk::RWRec, Net::Silk::IPSet, Net::Silk::Bag, Net::Silk::Pmap, Net::Silk::IPWildcard, Net::Silk::CIDR, Net::Silk::IPAddr, Net::Silk::TCPFlags, Net::Silk::ProtoPort, Net::Silk::File, Net::Silk::Site, silk(7)
COPYRIGHT & LICENSE
Copyright (C) 2016 by Carnegie Mellon University
Use of the Net-Silk library and related source code is subject to the terms of the following licenses:
GNU Public License (GPL) Rights pursuant to Version 2, June 1991 Government Purpose License Rights (GPLR) pursuant to DFARS 252.227.7013
NO WARRANTY
See GPL.txt and LICENSE.txt for more details.