1Lite(3)               User Contributed Perl Documentation              Lite(3)
2
3
4

NAME

6       Net::CIDR::Lite - Perl extension for merging IPv4 or IPv6 CIDR
7       addresses
8

SYNOPSIS

10         use Net::CIDR::Lite;
11
12         my $cidr = Net::CIDR::Lite->new;
13         $cidr->add($cidr_address);
14         @cidr_list = $cidr->list;
15         @ip_ranges = $cidr->list_range;
16

DESCRIPTION

18       Faster alternative to Net::CIDR when merging a large number of CIDR
19       address ranges. Works for IPv4 and IPv6 addresses.
20

METHODS

22       new()
23            $cidr = Net::CIDR::Lite->new
24            $cidr = Net::CIDR::Lite->new(@args)
25
26           Creates an object to represent a list of CIDR address ranges.  No
27           particular format is set yet; once an add method is called with a
28           IPv4 or IPv6 format, only that format may be added for this cidr
29           object. Any arguments supplied are passed to add_any() (see below).
30
31       add()
32            $cidr->add($cidr_address)
33
34           Adds a CIDR address range to the list.
35
36       add_range()
37            $cidr->add_range($ip_range)
38
39           Adds a hyphenated IP address range to the list.
40
41       add_cidr()
42            $cidr1->add_cidr($cidr2)
43
44           Adds address ranges from one object to another object.
45
46       add_ip()
47            $cidr->add_ip($ip_address)
48
49           Adds a single IP address to the list.
50
51       add_any()
52            $cidr->add_any($cidr_or_range_or_address);
53
54           Determines format of range or single ip address and calls add(),
55           add_range(), add_cidr(), or add_ip() as appropriate.
56
57       $cidr->clean()
58            $cidr->clean;
59
60           If you are going to call the list method more than once on the same
61           data, then for optimal performance, you can call this to purge null
62           nodes in overlapping ranges from the list. Boundary nodes in
63           contiguous ranges are automatically purged during add().  Only
64           useful when ranges overlap or when contiguous ranges are added out
65           of order.
66
67       $cidr->list()
68            @cidr_list = $cidr->list;
69            $list_ref  = $cidr->list;
70
71           Returns a list of the merged CIDR addresses. Returns an array if
72           called in list context, an array reference if not.
73
74       $cidr->list_range()
75            @cidr_list = $cidr->list_range;
76            $list_ref  = $cidr->list_range;
77
78           Returns a list of the merged addresses, but in hyphenated range
79           format. Returns an array if called in list context, an array
80           reference if not.
81
82       $cidr->list_short_range()
83            @cidr_list = $cidr->list_short_range;
84            $list_ref  = $cidr->list_short_range;
85
86           Returns a list of the C subnet merged addresses, in short
87           hyphenated range format. Returns an array if called in list
88           context, an array reference if not.
89
90           Example:
91
92                   1.1.1.1-2
93                   1.1.1.5-7
94                   1.1.1.254-255
95                   1.1.2.0-2
96                   1.1.3.5
97                   1.1.3.7
98
99       $cidr->find()
100            $found = $cidr->find($ip);
101
102           Returns true if the ip address is found in the CIDR range. False if
103           not.  Not extremely efficient, is O(n*log(n)) to sort the ranges in
104           the cidr object O(n) to search through the ranges in the cidr
105           object.  The sort is cached on the first call and used in
106           subsequent calls, but if more addresses are added to the cidr
107           object, prep_find() must be called on the cidr object.
108
109       $cidr->bin_find()
110           Same as find(), but forces a binary search. See also prep_find.
111
112       $cidr->prep_find()
113            $cidr->prep_find($num);
114
115           Caches the result of sorting the ip addresses. Implicitly called on
116           the first find call, but must be explicitly called if more
117           addresses are added to the cidr object. find() will do a binary
118           search if the number of ranges is greater than or equal to $num
119           (default 20);
120
121       $cidr->spanner()
122            $spanner = $cidr1->spanner($label1, $cidr2, $label2, ...);
123
124           Creates a spanner object to find out if multiple ip addresses are
125           within multiple labeled address ranges. May also be called as (with
126           or without any arguments):
127
128            Net::CIDR::Lite::Span->new($cidr1, $label1, $cidr2, $label2, ...);
129
130       $spanner->add()
131            $spanner->add($cidr1, $label1, $cidr2, $label2,...);
132
133           Adds labeled address ranges to the spanner object. The 'address
134           range' may be a Net::CIDR::Lite object, a single CIDR address
135           range, a single hyphenated IP address range, or a single IP
136           address.
137
138       $spanner->find()
139            $href = $spanner->find(@ip_addresses);
140
141           Look up which range(s) ip addresses are in, and return a lookup
142           table of the results, with the keys being the ip addresses, and the
143           value a hash reference of which address ranges the ip address is
144           in.
145
146       $spanner->bin_find()
147           Same as find(), but forces a binary search. See also prep_find.
148
149       $spanner->prep_find()
150            $spanner->prep_find($num);
151
152           Called implicitly the first time $spanner->find(..) is called, must
153           be called again if more cidr objects are added to the spanner
154           object. Will do a binary search if ratio of the number of ip
155           addresses to the number of ranges is less than $num percent
156           (default 4).
157
158       $spanner->clean()
159            $clean_address = $spanner->clean($ip_address);
160
161           Validates and returns a cleaned up version of an ip address (which
162           is what you will find as the key in the result from the
163           $spanner->find(..), not necessarily what the original argument
164           looked like). E.g. removes unnecessary leading zeros, removes null
165           blocks from IPv6 addresses, etc.
166

CAVEATS

168       Garbage in/garbage out. This module does do validation, but maybe not
169       enough to suit your needs.
170

AUTHOR

172       Douglas Wilson, <dougw@cpan.org> w/numerous hints and ideas borrowed
173       from Tye McQueen.
174

MAINTAINER

176       Stig Palmquist <stig@stig.io>
177
179        This module is free software; you can redistribute it and/or
180        modify it under the same terms as Perl itself.
181

SEE ALSO

183       Net::CIDR.
184
185
186
187perl v5.36.0                      2022-07-22                           Lite(3)
Impressum