Net-Subnets-1.02/000755 000765 000024 00000000000 11345563211 013544 5ustar00sristaff000000 000000 Net-Subnets-1.02/Changes000644 000765 000024 00000002011 11345562364 015041 0ustar00sristaff000000 000000 Revision history for Perl extension Net::Subnets. 1.02 2010-03-09 00:00:00 - Cleaned up tests. 1.01 2010-03-01 00:00:00 - Removed .perltidyrc. 1.0 2009-12-10 00:00:00 - Fixed everything. 0.21 2009-02-19 00:00:00 - Fixed pod. (Jan Harders) 0.20 2003-11-16 00:00:00 - Added list() function. - Better documentation. 0.19 2003-11-12 00:00:00 - Fixed a bug in subnets() and check() which produced false matches. (Eric Johanson) - Fixed the changelog. 0.18 2003-10-13 00:00:00 - Fixed some typos 0.17 2003-09-30 00:00:00 - Made the constructor inheritable. (Markus Thielmann) 0.16 2003-09-28 00:00:00 - Added range() function. 0.15 2003-09-15 00:00:00 - New test. 0.14 2003-09-13 00:00:00 - Better documentation. 0.13 2003-09-12 00:00:00 - Added example. 0.12 2003-09-11 00:00:00 - Fixed even more typos. 0.11 2003-09-10 00:00:00 - Fixed some typos. 0.10 2009-08-28 00:00:00 - first public release Net-Subnets-1.02/examples/000755 000765 000024 00000000000 11345563211 015362 5ustar00sristaff000000 000000 Net-Subnets-1.02/lib/000755 000765 000024 00000000000 11345563211 014312 5ustar00sristaff000000 000000 Net-Subnets-1.02/LICENSE000644 000765 000024 00000021276 11312750565 014565 0ustar00sristaff000000 000000 The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Net-Subnets-1.02/Makefile.PL000644 000765 000024 00000002071 11344465407 015525 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2003-2010, Sebastian Riedel. use strict; use warnings; use ExtUtils::MakeMaker; my $mm = $ExtUtils::MakeMaker::VERSION; # Son, when you participate in sporting events, # it's not whether you win or lose, it's how drunk you get. WriteMakefile( NAME => 'Net::Subnets', AUTHOR => 'Sebastian Riedel (sri@cpan.org)', VERSION_FROM => 'lib/Net/Subnets.pm', ($mm < 6.3002 ? () : ('LICENSE' => 'artistic_2')), ( $mm < 6.46 ? () : ( META_MERGE => { requires => {perl => '5.008001'}, resources => { license => 'http://dev.perl.org/licenses/', repository => 'http://github.com/kraih/net-subnets/tree/master' }, no_index => {directory => [qw/t/]} }, META_ADD => { build_requires => {}, configure_requires => {} }, ) ), PREREQ_PM => {'ExtUtils::MakeMaker' => 0, 'Test::More' => 0} ); Net-Subnets-1.02/MANIFEST000644 000765 000024 00000000401 11345563211 014670 0ustar00sristaff000000 000000 Changes examples/matching.pl lib/Net/Subnets.pm LICENSE Makefile.PL MANIFEST This list of files README t/01use.t t/02pod.t t/03podcoverage.t t/04check.t t/05range.t t/06list.t META.yml Module meta-data (added by MakeMaker) Net-Subnets-1.02/META.yml000644 000765 000024 00000001253 11345563211 015016 0ustar00sristaff000000 000000 --- #YAML:1.0 name: Net-Subnets version: 1.02 abstract: ~ author: - Sebastian Riedel (sri@cpan.org) license: artistic_2 distribution_type: module configure_requires: {} build_requires: {} requires: ExtUtils::MakeMaker: 0 perl: 5.008001 Test::More: 0 resources: license: http://dev.perl.org/licenses/ repository: http://github.com/kraih/net-subnets/tree/master no_index: directory: - t - inc - t generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Net-Subnets-1.02/README000644 000765 000024 00000000225 11312755112 014420 0ustar00sristaff000000 000000 Computing Subnets In Large Scale Networks. To install this module type the following: perl Makefile.PL make make test make install Net-Subnets-1.02/t/000755 000765 000024 00000000000 11345563211 014007 5ustar00sristaff000000 000000 Net-Subnets-1.02/t/01use.t000644 000765 000024 00000000233 11345562475 015142 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2003-2010, Sebastian Riedel. use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok('Net::Subnets') } Net-Subnets-1.02/t/02pod.t000644 000765 000024 00000000554 11344465465 015137 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2005-2010, Sebastian Riedel. use strict; use warnings; use Test::More; eval "use Test::Pod 1.14"; plan skip_all => 'Test::Pod 1.14 required' if $@; plan skip_all => 'set TEST_POD to enable this test (developer only!)' unless $ENV{TEST_POD}; # Marge, it takes two to lie. One to lie and one to listen. all_pod_files_ok(); Net-Subnets-1.02/t/03podcoverage.t000644 000765 000024 00000000654 11345562605 016650 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2005-2010, Sebastian Riedel. use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; plan skip_all => 'set TEST_POD to enable this test (developer only!)' unless $ENV{TEST_POD}; # Marge, I'm going to miss you so much. And it's not just the sex. # It's also the food preparation. all_pod_coverage_ok(); Net-Subnets-1.02/t/04check.t000644 000765 000024 00000000743 11345562703 015426 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2003-2010, Sebastian Riedel. use strict; use warnings; use Test::Simple tests => 4; use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.0/24); my @good_addr = qw(10.0.0.1 10.0.1.2); my @bad_addr = qw(10.0.3.4 20.0.0.1); my $sn = Net::Subnets->new; $sn->subnets(\@subnets); foreach my $addr (@good_addr) { ok($sn->check(\$addr), 'address is good'); } foreach my $addr (@bad_addr) { ok(!$sn->check(\$addr), 'address is bad'); } Net-Subnets-1.02/t/05range.t000644 000765 000024 00000000745 11345563006 015445 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2003-2010, Sebastian Riedel. use strict; use warnings; use Test::Simple tests => 2; use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.4/32); my @lowips = qw(10.0.0.1 10.0.1.4); my @highips = qw(10.0.0.254 10.0.1.4); my $sn = Net::Subnets->new; for (my $i = 0; $i <= $#subnets; $i++) { my ($lowip, $highip) = $sn->range(\$subnets[$i]); ok((($lowips[$i] eq $$lowip) && ($highips[$i] eq $$highip)), 'right address range'); } Net-Subnets-1.02/t/06list.t000644 000765 000024 00000013137 11345563041 015323 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2003-2010, Sebastian Riedel. use strict; use warnings; use Test::Simple tests => 510; use Net::Subnets; my $subnet = '10.0.0.0/23'; my $sn = Net::Subnets->new; my $list = $sn->list($sn->range(\$subnet)); while () { chomp; ok(($_ eq $$list[$. - 1]), 'right list'); } __DATA__ 10.0.0.1 10.0.0.2 10.0.0.3 10.0.0.4 10.0.0.5 10.0.0.6 10.0.0.7 10.0.0.8 10.0.0.9 10.0.0.10 10.0.0.11 10.0.0.12 10.0.0.13 10.0.0.14 10.0.0.15 10.0.0.16 10.0.0.17 10.0.0.18 10.0.0.19 10.0.0.20 10.0.0.21 10.0.0.22 10.0.0.23 10.0.0.24 10.0.0.25 10.0.0.26 10.0.0.27 10.0.0.28 10.0.0.29 10.0.0.30 10.0.0.31 10.0.0.32 10.0.0.33 10.0.0.34 10.0.0.35 10.0.0.36 10.0.0.37 10.0.0.38 10.0.0.39 10.0.0.40 10.0.0.41 10.0.0.42 10.0.0.43 10.0.0.44 10.0.0.45 10.0.0.46 10.0.0.47 10.0.0.48 10.0.0.49 10.0.0.50 10.0.0.51 10.0.0.52 10.0.0.53 10.0.0.54 10.0.0.55 10.0.0.56 10.0.0.57 10.0.0.58 10.0.0.59 10.0.0.60 10.0.0.61 10.0.0.62 10.0.0.63 10.0.0.64 10.0.0.65 10.0.0.66 10.0.0.67 10.0.0.68 10.0.0.69 10.0.0.70 10.0.0.71 10.0.0.72 10.0.0.73 10.0.0.74 10.0.0.75 10.0.0.76 10.0.0.77 10.0.0.78 10.0.0.79 10.0.0.80 10.0.0.81 10.0.0.82 10.0.0.83 10.0.0.84 10.0.0.85 10.0.0.86 10.0.0.87 10.0.0.88 10.0.0.89 10.0.0.90 10.0.0.91 10.0.0.92 10.0.0.93 10.0.0.94 10.0.0.95 10.0.0.96 10.0.0.97 10.0.0.98 10.0.0.99 10.0.0.100 10.0.0.101 10.0.0.102 10.0.0.103 10.0.0.104 10.0.0.105 10.0.0.106 10.0.0.107 10.0.0.108 10.0.0.109 10.0.0.110 10.0.0.111 10.0.0.112 10.0.0.113 10.0.0.114 10.0.0.115 10.0.0.116 10.0.0.117 10.0.0.118 10.0.0.119 10.0.0.120 10.0.0.121 10.0.0.122 10.0.0.123 10.0.0.124 10.0.0.125 10.0.0.126 10.0.0.127 10.0.0.128 10.0.0.129 10.0.0.130 10.0.0.131 10.0.0.132 10.0.0.133 10.0.0.134 10.0.0.135 10.0.0.136 10.0.0.137 10.0.0.138 10.0.0.139 10.0.0.140 10.0.0.141 10.0.0.142 10.0.0.143 10.0.0.144 10.0.0.145 10.0.0.146 10.0.0.147 10.0.0.148 10.0.0.149 10.0.0.150 10.0.0.151 10.0.0.152 10.0.0.153 10.0.0.154 10.0.0.155 10.0.0.156 10.0.0.157 10.0.0.158 10.0.0.159 10.0.0.160 10.0.0.161 10.0.0.162 10.0.0.163 10.0.0.164 10.0.0.165 10.0.0.166 10.0.0.167 10.0.0.168 10.0.0.169 10.0.0.170 10.0.0.171 10.0.0.172 10.0.0.173 10.0.0.174 10.0.0.175 10.0.0.176 10.0.0.177 10.0.0.178 10.0.0.179 10.0.0.180 10.0.0.181 10.0.0.182 10.0.0.183 10.0.0.184 10.0.0.185 10.0.0.186 10.0.0.187 10.0.0.188 10.0.0.189 10.0.0.190 10.0.0.191 10.0.0.192 10.0.0.193 10.0.0.194 10.0.0.195 10.0.0.196 10.0.0.197 10.0.0.198 10.0.0.199 10.0.0.200 10.0.0.201 10.0.0.202 10.0.0.203 10.0.0.204 10.0.0.205 10.0.0.206 10.0.0.207 10.0.0.208 10.0.0.209 10.0.0.210 10.0.0.211 10.0.0.212 10.0.0.213 10.0.0.214 10.0.0.215 10.0.0.216 10.0.0.217 10.0.0.218 10.0.0.219 10.0.0.220 10.0.0.221 10.0.0.222 10.0.0.223 10.0.0.224 10.0.0.225 10.0.0.226 10.0.0.227 10.0.0.228 10.0.0.229 10.0.0.230 10.0.0.231 10.0.0.232 10.0.0.233 10.0.0.234 10.0.0.235 10.0.0.236 10.0.0.237 10.0.0.238 10.0.0.239 10.0.0.240 10.0.0.241 10.0.0.242 10.0.0.243 10.0.0.244 10.0.0.245 10.0.0.246 10.0.0.247 10.0.0.248 10.0.0.249 10.0.0.250 10.0.0.251 10.0.0.252 10.0.0.253 10.0.0.254 10.0.0.255 10.0.1.0 10.0.1.1 10.0.1.2 10.0.1.3 10.0.1.4 10.0.1.5 10.0.1.6 10.0.1.7 10.0.1.8 10.0.1.9 10.0.1.10 10.0.1.11 10.0.1.12 10.0.1.13 10.0.1.14 10.0.1.15 10.0.1.16 10.0.1.17 10.0.1.18 10.0.1.19 10.0.1.20 10.0.1.21 10.0.1.22 10.0.1.23 10.0.1.24 10.0.1.25 10.0.1.26 10.0.1.27 10.0.1.28 10.0.1.29 10.0.1.30 10.0.1.31 10.0.1.32 10.0.1.33 10.0.1.34 10.0.1.35 10.0.1.36 10.0.1.37 10.0.1.38 10.0.1.39 10.0.1.40 10.0.1.41 10.0.1.42 10.0.1.43 10.0.1.44 10.0.1.45 10.0.1.46 10.0.1.47 10.0.1.48 10.0.1.49 10.0.1.50 10.0.1.51 10.0.1.52 10.0.1.53 10.0.1.54 10.0.1.55 10.0.1.56 10.0.1.57 10.0.1.58 10.0.1.59 10.0.1.60 10.0.1.61 10.0.1.62 10.0.1.63 10.0.1.64 10.0.1.65 10.0.1.66 10.0.1.67 10.0.1.68 10.0.1.69 10.0.1.70 10.0.1.71 10.0.1.72 10.0.1.73 10.0.1.74 10.0.1.75 10.0.1.76 10.0.1.77 10.0.1.78 10.0.1.79 10.0.1.80 10.0.1.81 10.0.1.82 10.0.1.83 10.0.1.84 10.0.1.85 10.0.1.86 10.0.1.87 10.0.1.88 10.0.1.89 10.0.1.90 10.0.1.91 10.0.1.92 10.0.1.93 10.0.1.94 10.0.1.95 10.0.1.96 10.0.1.97 10.0.1.98 10.0.1.99 10.0.1.100 10.0.1.101 10.0.1.102 10.0.1.103 10.0.1.104 10.0.1.105 10.0.1.106 10.0.1.107 10.0.1.108 10.0.1.109 10.0.1.110 10.0.1.111 10.0.1.112 10.0.1.113 10.0.1.114 10.0.1.115 10.0.1.116 10.0.1.117 10.0.1.118 10.0.1.119 10.0.1.120 10.0.1.121 10.0.1.122 10.0.1.123 10.0.1.124 10.0.1.125 10.0.1.126 10.0.1.127 10.0.1.128 10.0.1.129 10.0.1.130 10.0.1.131 10.0.1.132 10.0.1.133 10.0.1.134 10.0.1.135 10.0.1.136 10.0.1.137 10.0.1.138 10.0.1.139 10.0.1.140 10.0.1.141 10.0.1.142 10.0.1.143 10.0.1.144 10.0.1.145 10.0.1.146 10.0.1.147 10.0.1.148 10.0.1.149 10.0.1.150 10.0.1.151 10.0.1.152 10.0.1.153 10.0.1.154 10.0.1.155 10.0.1.156 10.0.1.157 10.0.1.158 10.0.1.159 10.0.1.160 10.0.1.161 10.0.1.162 10.0.1.163 10.0.1.164 10.0.1.165 10.0.1.166 10.0.1.167 10.0.1.168 10.0.1.169 10.0.1.170 10.0.1.171 10.0.1.172 10.0.1.173 10.0.1.174 10.0.1.175 10.0.1.176 10.0.1.177 10.0.1.178 10.0.1.179 10.0.1.180 10.0.1.181 10.0.1.182 10.0.1.183 10.0.1.184 10.0.1.185 10.0.1.186 10.0.1.187 10.0.1.188 10.0.1.189 10.0.1.190 10.0.1.191 10.0.1.192 10.0.1.193 10.0.1.194 10.0.1.195 10.0.1.196 10.0.1.197 10.0.1.198 10.0.1.199 10.0.1.200 10.0.1.201 10.0.1.202 10.0.1.203 10.0.1.204 10.0.1.205 10.0.1.206 10.0.1.207 10.0.1.208 10.0.1.209 10.0.1.210 10.0.1.211 10.0.1.212 10.0.1.213 10.0.1.214 10.0.1.215 10.0.1.216 10.0.1.217 10.0.1.218 10.0.1.219 10.0.1.220 10.0.1.221 10.0.1.222 10.0.1.223 10.0.1.224 10.0.1.225 10.0.1.226 10.0.1.227 10.0.1.228 10.0.1.229 10.0.1.230 10.0.1.231 10.0.1.232 10.0.1.233 10.0.1.234 10.0.1.235 10.0.1.236 10.0.1.237 10.0.1.238 10.0.1.239 10.0.1.240 10.0.1.241 10.0.1.242 10.0.1.243 10.0.1.244 10.0.1.245 10.0.1.246 10.0.1.247 10.0.1.248 10.0.1.249 10.0.1.250 10.0.1.251 10.0.1.252 10.0.1.253 10.0.1.254 Net-Subnets-1.02/lib/Net/000755 000765 000024 00000000000 11345563211 015040 5ustar00sristaff000000 000000 Net-Subnets-1.02/lib/Net/Subnets.pm000644 000765 000024 00000010426 11345562376 017037 0ustar00sristaff000000 000000 # Copyright (C) 2003-2010, Sebastian Riedel. package Net::Subnets; use strict; use vars qw/$VERSION/; $VERSION = '1.02'; sub new { my $self = shift; return bless({}, (ref($self) || $self)); } sub subnets { my ($self, $subnets) = @_; my %masks; foreach (@$subnets) { /^(.+?)\/(.+)$/o; my $revmask = 32 - ($2 || 32); $self->{subnets}{$revmask} {unpack("N", pack("C4", split(/\./, $1))) >> $revmask} = $_; $masks{$revmask}++; } @{$self->{masks}} = sort({$masks{$a} <=> $masks{$b}} keys(%masks)); } sub check { my ($self, $address) = @_; foreach (@{$self->{masks}}) { my $option = unpack("N", pack("C4", split(/\./, $$address))) >> $_; if ($self->{subnets}{$_}{$option}) { return \($self->{subnets}{$_}{$option}); } } return 0; } sub range { my ($self, $subnet) = @_; $$subnet =~ /^(.+?)\/(.+)$/o; my $net = pack('C4', split(/\./, $1)) & pack('B*', (1 x $2) . (0 x (32 - ($2 || 32)))); my $lowip = join('.', unpack('C4', pack('B*', (0 x 31) . 1) | $net)); my $highip = join('.', unpack('C4', pack('B*', (0 x $2) . (1 x (31 - $2)) . 0) | $net)); if ($2 == 32) { return (\$highip, \$highip); } return (\$lowip, \$highip); } sub list { my ($self, $lowip, $highip) = @_; my $lowint = unpack("N", pack("C4", split(/\./, $$lowip))); my $highint = unpack("N", pack("C4", split(/\./, $$highip))); my @list = (join('.', unpack('C4', pack('N', $lowint)))); while ($lowint lt $highint) { push(@list, join('.', unpack('C4', pack('N', ++$lowint)))); } return \@list; } 1; __END__ =head1 NAME Net::Subnets - Computing Subnets In Large Scale Networks =head1 SYNOPSIS use Net::Subnets; my $sn = Net::Subnets->new; $sn->subnets(\@subnets); if (my $subnetref = $sn->check(\$address)) { ... } my ($lowipref, highipref) = $sn->range(\$subnet); my $listref = $sn->list(\($lowipref, $highipref)); =head1 DESCRIPTION Very fast matches large lists of IP addresses against many CIDR subnets and calculates IP address ranges. This is a simple and efficient example for subnet matching: use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.0/24); my @addresses = qw/10.0.0.1 10.0.1.2 10.0.3.1/; my $sn = Net::Subnets->new; $sn->subnets(\@subnets); my $results; foreach my $address (@addresses) { if (my $subnetref = $sn->check(\$address)) { $results .= "$address: $$subnetref\n"; } else { $results .= "$address: not found\n"; } } print($results); This is a simple example for range calculation: use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.0/24); my $sn = Net::Subnets->new; my $results; foreach my $subnet (@subnets) { my ($lowipref, $highipref) = $sn->range(\$subnet); $results .= "$subnet: $$lowipref - $$highipref\n"; } print( $results ); This is a simple example for list generation: use Net::Subnets; my $lowip = '192.168.0.1'; my $highip = '192.168.0.100'; my $sn = Net::Subnets->new; my $listref = $sn->list(\($lowip, $highip)); foreach my $address (@$listref) { # do something cool } =head1 METHODS =head2 C my $subnets = Net::Subnets->new; Creates an "Net::Subnets" object. =head2 C $subnets->subnets([qw(10.0.0.0/24 10.0.1.0/24)]); The C method lets you prepare a list of CIDR subnets. =head2 C my $match = $subnets->check(\$address); The C method lets you check an IP address against the previously prepared subnets. =head2 C my ($lowest, $highest) = $subnets->range(\$subnet) The C method lets you calculate the IP address range of a subnet. =head2 C my $list = $subnets->list(\$lowest, $highest); The C method lets you calculate a list containing all IP addresses in a given range. =head1 AUTHOR Sebastian Riedel (sri@cpan.org), Juergen Peters (juergen.peters@taulmarill.de) =head1 COPYRIGHT AND LICENSE Copyright (C) 2003-2010, Sebastian Riedel. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. =cut Net-Subnets-1.02/examples/matching.pl000644 000765 000024 00000000720 11344465376 017524 0ustar00sristaff000000 000000 #!/usr/bin/env perl # Copyright (C) 2003-2010, Sebastian Riedel. use Net::Subnets; my @subnets = qw(10.0.0.0/24 10.0.1.0/24); my @addresses = qw/10.0.0.1 10.0.1.2 10.0.3.1/; my $sn = Net::Subnets->new; $sn->subnets(\@subnets); my $results; foreach my $address (@addresses) { if (my $subnetref = $sn->check(\$address)) { $results .= "$address: $$subnetref\n"; } else { $results .= "$address: not found\n"; } } print($results);