The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::Silk::IPSet - SiLK IP sets

SYNOPSIS

  use Net::Silk::IPSet;

DESCRIPTION

Net::Silk::IPSet objects represent a set of IP addresses, as produced by rwset(1) and rwsetbuild(1).

METHODS

A number of the following methods accept a list of items as arguments. The items can be any of the following:

  * Net::Silk::IPAddr or string representation
  * Net::Silk::IPWildcard or string representation
  * Net::Silk::IPSet
  * string representation of a CIDR block (x.x.x.x/n)
  * string representation of a range (x.x.x.x-y.y.y.y)
  * ref to array containing any of the above

The following methods are available:

CONSTRUCTORS

new(...)

Returns a new Net::Silk::IPSet object. Any arguments are passed to the add() method of the newly created set, so therefore accepts an item list as described above.

load($file)

Return a new Net::Silk::IPSet object loaded from the given SiLK IPSet file.

copy()

Returns a copy of this IPSet object.

save($file)

Save the IPSet as a SiLK IPSet file with the given name.

QUERY METHODS

cardinality()

Return a count of how many IP addresses are in this set.

contains($ip)

Return true if the given IP address is present in this set.

supports_ipv6()

Return true if this set supports IPv6.

is_subset(...)

Return true if this set is a subset of the union of the given item list.

is_superset(...)

Return true if this set is a superset of the union of the given item list.

is_disjoint($item)

Return true if this set has no members in common with the union of the given item list.

difference(...)

Return a new Net::Silk::IPSet containing IP addresses in this set but not in the union of the given item list.

intersection(...)

Return a new Net::Silk::IPSet representing IP addresses present in both this set and the union of the given item list.

symmetric_difference($item)

Return a new Net::Silk::IPSet containing IP addresses found in either this set or the union of the given item list, but not both.

union($item)

Return a new Net::Silk::IPSet representing IP addresses present in either this set or the given item list.

iter()

Return a sub ref iterator that returns each IP address present in this set. These IP addresses can also be obtained by using the IO operator on this object <$ipset>.

iter_cidr()

Return a sub ref iterator that, upon each invocation, returns a ref to an array containing the IP address and prefix of each CIDR block present in this set.

MANIPULATION METHODS

pop()

Remove and return a random IP address from this set.

add(...)

Add all items in the provided item list to this set.

add_addr($ip)

Specifically add an IP address (string or object) to this set.

add_cidr($ip, $prefix)
add_cidr($cidr)

Specifically add a CIDR block to this set. A single argument can be provided as a string representation of the CIDR block (x.x.x.x/n).

add_range($low, $high)
add_range($range)

Specifically add the given range of IP addresses (string or object) to this set, inclusive. A single argument can be provided as a string representation of a range (x.x.x.x-y.y.y.y).

add_wildcard($wc)

Specifically add an IPwildcard (string or object) to this set.

remove(...)

Remove all items in the provided item list from this set.

remove_addr($ip)

Specifically remove an IP address (string or object) from this set.

remove_cidr($ip, $prefix)
remove_cidr($cidr)

Specifically remove a CIDR block from this set. A single argument can be provided as a string representation of the CIDR block (x.x.x.x/n).

remove_range($low, $high)
remove_range($range)

Specifically remove the given range of IP addresses (string or object) from this set, inclusive. A single argument can be provided as a string representation of a range (x.x.x.x-y.y.y.y).

remove_wildcard($wc)

Specifically remove an IPWildcard (string or object) from this set.

difference_update(...)

Remove from this set all IP addresses present in the union of the provided item list.

intersection_update($item)

Remove from this set all IP addresses not present in both this set as well as the union of the provided item list.

symmetric_difference_update($item)

Update this set, retaining the IP addresses found in this set or in the union of the provided item list, but not in both.

union_update($item)
update($item)

Add to this set all IP addresses present in the given item list.

clear()

Remove all IP addresses from this set.

OPERATORS

The following operators are overloaded and work with Net::Silk::TCPFlags objects:

  &             ==
  |             !=
  -             cmp
  ^             gt
  &=            lt
  |=            ge
  -=            le
  ^=            eq
  <=>           ne
  >             ""
  <             bool
  >=            <>
  <=            %{}

TIED HASH

The IPSet object reference can be treated like a hash reference, with each key being an IP address with a value of 1. So containment can be tested with if ($ipset-{$ip}) { ... }>

SEE ALSO

Net::Silk, Net::Silk::RWRec, Net::Silk::IPWildcard, Net::Silk::Bag, Net::Silk::Pmap, Net::Silk::IPAddr, Net::Silk::TCPFlags, Net::Silk::ProtoPort, Net::Silk::File, Net::Silk::Site, silk(7)

COPYRIGHT & LICENSE

Copyright (C) 2011-2014 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.