Net::IP::CMatch(3)
β¨ Net::IP::CMatch β¨
okay bestie, welcome to Net::IP::CMatch(3) π this is the perl module that lets you check IP addresses against IP ranges, except it does it in C so it's fast fast fast π₯
πΈ NAME πΈ
Net::IP::CMatch β match IP addresses against IP ranges, but efficiently, and with C. slay. π
π SYNOPSIS π
use Net::IP::CMatch;
my $match = match_ip( $ip_addr, $match_ip1, $match_ip2, ... );
π¦ DESCRIPTION π¦
so like, Net::IP::CMatch is based upon Net::IP::Match, and it literally does the same thing, no cap. it unconditionally exports one subroutine called match_ip, and what that does is figure out if the ip you want to match (that's the first argument, bestie) matches any of the ip arguments that come after it. β¨
those match arguments can be absolute quads like '127.0.0.1', or they can have mask bits like '111.245.76.248/29'. a true return value means yes, it matched, periodt. π
the whole reason this thing exists in C instead of as a macro preprocessed through Perl's source filter mechanism (which is what Net::IP::Match does) is so that the ip arguments could just be normal traditional perl scalars. and the C code? lean and mean (IMHO). π
π Example in Apache/mod_perl π
ngl I (the author) use this module in my Apache server's mod_perl DB logging script to work out whether an incoming IP is 'remote' or 'local'. first step, set up some variables in httpd.conf:
PerlSetvar DBILogger_local_ips '222.234.52.192/29'
PerlAddvar DBILogger_local_ips '111.245.76.248/29'
PerlAddvar DBILogger_local_ips '10.0.0.0/24'
PerlAddvar DBILogger_local_ips '172.16.0.0/12'
PerlAddvar DBILogger_local_ips '192.168.0.0/16'
PerlAddvar DBILogger_local_ips '127.0.0.1'
these are the ip addresses I want to be considered local, iykyk. and then in the mod_perl module:
my @local_ips = $r->dir_config( "DBILogger_local_ips" );
my $local = match_ip( $incoming_ip, @local_ips );
and now $local is just... that. it's exactly what it sounds like. so I set the database key accordingly and we move on with our lives π«Ά
π EXPORT π
'match_ip', unconditionally. that's it, that's the whole export list. no choices to make, no opt-in, it's just there. main character energy honestly π
π SEE ALSO π
Net::IP::Match by Marcel GrΓΌnauer. go give it a look, it's the ancestor of all this π§
π AUTHOR π
Beau E. Cox, <beaucox@hawaii.rr.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2004 by Beau E. Cox
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available. π
ok so that's the whole page, bestie. every flag, every path, every word. no notes. π
and a lil sign-off for the road: this was perl v5.42.0, dated 2025-07-25, and the manual page is Net::IP::CMatch(3). go match some IPs, you're gonna ate πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Net-IP-CMatch 0.02-60.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms