Net::IP::CMatch(3)

πŸ“¦
version 0.02 Β· 2 versions
, in fedora 43

✨ 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 (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