|
|
| Official Guide to Programming with CGI.pm (ISBN: 0471247448) |
 |
List Price: $39.99
Our Price: $27.99
Used Price: $14.47
Release Date: 03 April, 1998
Manufacturer: John Wiley & Sons (Paperback)
Sales Rank: 84,609
Author: Lincoln Stein
|
More Info
|
|
|
IP Filter
|
2002-08-11 10:12:00
|
| |
perl
|
|
|
|
|
Category: source:perl:cgi
|
|
Description: This script is an example of how to deny access to a specific webpage or multiple pages by using the remote user's IP address.
|
|
Platform: unix
|
|
Author: Snap
|
|
Viewed: 2640
|
|
Rating: 3/5 (7 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
#!/usr/bin/perl
print "Content text:html/text\n\n";
##########################################
# #
# Written by Snap #
# (iam@someoneshouse.com) #
# #
# For Metalshell #
# http://www.metalshell.com #
# #
# This script is an example of how to #
# deny access to a specific webpage or #
# multiple pages by using the remote #
# user's IP Address. It matches each #
# incomming IP against a list you define#
# and then allows or denies accordingly #
# #
##########################################
### This is the list of IP's you want to allow to access this page ###
@allow=("192.168.1.101","192.168.1.102","192.168.1.103","192.168.1.104");
### Change the below line to accomidate for the page you want to hide ###
$hidden="hidden.html";
### Get the Users IP Address ###
$userAddr=$ENV{REMOTE_ADDR};
### Set Default to Deny ###
$TestVar="0";
### This loop checks the Users IP against the Given List ###
foreach $i (@allow){
### If the IP is found in the list, change switch ###
if($i eq $userAddr){
$TestVar="1";
}
}#-#-#End Of Foreach
### If the IP address is accepted, open your hidden html file ###
if($TestVar == 1){
open(NEWT,"$hidden");
while(<NEWT>)
{
$HTML=$HTML.$_;
}
close NEWT;
print "$HTML\n";
}
### Else, display a deny page (Completely Customizable) ###
elsif($TestVar == 0){
print<<STOP
<html>
<title>Access Denied<\/title>
<body bgcolor=red>
<font size=6 color=black>
<u>Access Denied<\/u>
<\/font>
<br><br>
<b>
Your IP Address $userAddr has been denied Access to this page.<br>
If you feel this is in error, please contact the
<a href=mailto:$ENV{SERVER_ADMIN}>administrator<\/a>.
<\/b>
<\/body>
<\/html>
STOP
}
|
|
|