On the Internet, many solutions to this problem, I also searched for it, but I did not like solutions because I didn’t like it with my performance. In Perl, there is the Net :: Patricia package, which solves this problem very effectively, the method is based on the Patricia Tree.
You can install this package through CPAN.
perl -MCPAN -e shell install Net :: Patricia ')
After installation, you can use this package as follows:
#!/usr/bin/perl -w use Net::Patricia; # IP tools my $pt = new Net::Patricia; $pt->add_string('212.44.12.0/24'); if(defined($pt->match_string('212.44.12.3'))){ print "IN\n"; }else{ print "OUT\n"; }