1Net::IP::CMatch(3) User Contributed Perl Documentation Net::IP::CMatch(3)
2
3
4
6 Net::IP::CMatch - Efficiently match IP addresses against IP ranges with
7 C.
8
10 use Net::IP::CMatch;
11 my $match = match_ip( $ip_addr, $match_ip1, $match_ip2, ... );
12
14 Net::IP::CMatch is based upon, and does the same thing as
15 Net::IP::Match. The unconditionally exported subroutine 'match_ip'
16 determines if the ip to match ( first argument ) matches any of the
17 subsequent ip arguments. Match arguments may be absolute quads, as
18 '127.0.0.1', or contain mask bits as '111.245.76.248/29'. A true
19 return value indicates a match. It was written in C, rather than a
20 macro, preprocessed through Perl's source filter mechanism ( as is
21 Net::IP::Match ), so that the ip arguments could be traditional perl
22 scalars. The C code is lean and mean ( IMHO ).
23
24 Example in Apache/mod_perl
25 I use this module in my Apache server's mod_perl DB logging script to
26 determine if an incoming IP is 'remote' or 'local'. First, I set up
27 some variables in httpd.conf:
28
29 PerlSetvar DBILogger_local_ips '222.234.52.192/29'
30 PerlAddvar DBILogger_local_ips '111.245.76.248/29'
31 PerlAddvar DBILogger_local_ips '10.0.0.0/24'
32 PerlAddvar DBILogger_local_ips '172.16.0.0/12'
33 PerlAddvar DBILogger_local_ips '192.168.0.0/16'
34 PerlAddvar DBILogger_local_ips '127.0.0.1'
35
36 These are the ip addresses I want to be considered local. In the
37 mod_perl module:
38
39 my @local_ips = $r->dir_config( "DBILogger_local_ips" );
40 my $local = match_ip( $incoming_ip, @local_ips );
41
42 Now $local is just that, and I set the database key accordingly.
43
44 EXPORT
45 'match_ip', unconditionally.
46
48 Net::IP::Match by Marcel GrĂ¼nauer.
49
51 Beau E. Cox, <beaucox@hawaii.rr.com>
52
54 Copyright (C) 2004 by Beau E. Cox
55
56 This library is free software; you can redistribute it and/or modify it
57 under the same terms as Perl itself, either Perl version 5.6.1 or, at
58 your option, any later version of Perl 5 you may have available.
59
60
61
62perl v5.32.0 2020-07-28 Net::IP::CMatch(3)