I have a script which checks the users ip, then checks a db to see if it is in it, and if it is, routes the user to a specific page, therefore denying access to a restricted area.
The db is a .txt file, and uses ranges of ip's (ie 123.45.) and bans all ips under it. Rather than listing all the ips to ban, I would rather ban the range, but allow certain ips withing that banned range.. (ie ban 123.45.xxx.xxx, but allow 123.45.22.1)
Here is the script that is in use..
*******
sub CheckBadIP{
open(DB,"../admindir/badip.txt"
while(<DB>){
chomp;
$ip{$_} = 1;
}
close DB;
#print "\n";
$badip = 0;
foreach $i (keys %ip){
next if (!$i);
$i =~ s/\./\\./g;
($ENV{'REMOTE_ADDR'} =~ /^$i/)&&($badip=1);
# print "($ENV{'REMOTE_ADDR'} =~ /$i/)&&($badip=1);\n";
}
if($badip){
&SendEmailError;
print "Location: /sorry.htm\n\n";
exit;
}
}
*******
so what I would like, is to have another .txt db named goodip.txt that would check if in bad range, and allow if in goodip.txt
Does this make sense?
Thanks for any help..
The db is a .txt file, and uses ranges of ip's (ie 123.45.) and bans all ips under it. Rather than listing all the ips to ban, I would rather ban the range, but allow certain ips withing that banned range.. (ie ban 123.45.xxx.xxx, but allow 123.45.22.1)
Here is the script that is in use..
*******
sub CheckBadIP{
open(DB,"../admindir/badip.txt"
while(<DB>){
chomp;
$ip{$_} = 1;
}
close DB;
#print "\n";
$badip = 0;
foreach $i (keys %ip){
next if (!$i);
$i =~ s/\./\\./g;
($ENV{'REMOTE_ADDR'} =~ /^$i/)&&($badip=1);
# print "($ENV{'REMOTE_ADDR'} =~ /$i/)&&($badip=1);\n";
}
if($badip){
&SendEmailError;
print "Location: /sorry.htm\n\n";
exit;
}
}
*******
so what I would like, is to have another .txt db named goodip.txt that would check if in bad range, and allow if in goodip.txt
Does this make sense?
Thanks for any help..