RewriteEngine on
Rewritemap blacklist txt:/path/to/blacklist.txt
RewriteCond ${blacklist:%{REMOTE_ADDR}} =b
RewriteCond %{request_uri} !=/sorry.html
RewriteRule .* /sorry.html                       [R,L]
>cat /path/to/blacklist.txt
193.220.137.2 b
81.199.171.20 b
<Limit GET HEAD POST>
order allow,deny
deny from 202.70.112.0/20
allow from all
</LIMIT>
Générateur de classes IP (par pays) en ligne : http://blockacountry.com
- Dynamique (ex. par pays) :
Avec la liste ip-to-country et un script Perl du style :
#!/usr/bin/perl -w
use strict;
my %ip;
my $old_ip=0;
while (<>) {
my ($ip) = split;
next if ($ip eq $old_ip);
my ($a,$b,$c,$d) = split(/\./,$ip);
my $n = ((((($a * 256) + $b) * 256) + $c) * 256) +$d;
open (FILE,"< ip-to-country.csv") || die $!;
while (<FILE>) {
my ($beg,$end,$country) = (split (/,/,$_))[0,1,4];
$beg =~ s/"//g;
$end =~ s/"//g;
if (($beg <= $n) and ($end >= $n)) {
$ip{$ip}++;
print "ip = $ip\n";
last;
}}
close(FILE);
$old_ip=$ip;
}
exit(0);
Commentaires récents