Here is the code and the files that you need to create:
Create a file called: IPblock.asp
and in it add the following:
<%
'#############################################################################
'NAME: IPBlock.asp
'Description: IPBlock IP banning script.
'Dependancies: ipbanlist.inc
'
'************** MOD Log ************************
'Name Date Mod/Reason
'------------------------------------------------
'Jeremy Mann 04/02/03 Inital Release
'#############################################################################
' Detects a cookie from this script ifthis user has been banned before
IF Request.Cookies(strCookieURL & "banned") = "yes" THEN
' Cookie has been detected, so this user was previously banned
' Where you want to send the banned user
Response.Redirect "http://www.ImportOutfitters.com/****off.asp"
ELSE
' Cookie has NOT been detected, so this user was NOT previously banned
dim bannedipcount
dim IPbanRecord(45,45)
IPtoCheck=split(request.ServerVariables("remote_addr"),".")
' Path to the textfile of banned IP's
Banned_IP_File_Path=server.MapPath("include/ipbanlist.inc")
set IPBanlistObject = server.CreateObject("scripting.filesystemobject")
set myfile = IPBanlistObject.OpenTextFile(Banned_IP_File_Path)
i=1
bannedipcount = 0
' Begin to readin the file containing the band IP's
while not myfile.atendofstream
line=myfile.readline
tempvar=split(line,"-")
IPbanRecord(i,1)=tempvar(0)
IPbanRecord(i,2)=tempvar(1)
' When finished "bannedipcount" will retun how many banned IP's there are, to later load in an array
bannedipcount = myfile.line
i=i+1
wend
myfile.close
flag=false
j=1
while j<= bannedipcount
LowerboundIP=split(IPbanRecord(j,1),".")
UpperboundIP=split(IPbanRecord(j,2),".")
if IPtoCheck(0) >= LowerboundIP(0) and IPtoCheck(0) <= UpperboundIP(0) then
if IPtoCheck(1) >= LowerboundIP(1) and IPtoCheck(1) <= UpperboundIP(1) then
if IPtoCheck(2) >= LowerboundIP(2) and IPtoCheck(2) <= UpperboundIP(2) then
if IPtoCheck(3) >= LowerboundIP(3) and IPtoCheck(3) <= UpperboundIP(3) then
flag=true
end if
end if
end if
end if
if flag=true then
' ###### Users IP is in the ban list
' 'set a cookie(incase user tries to later use a proxy box to bypass the IP banning)
Response.Cookies(strCookieURL & "banned") = "yes"
' Redirect the banned user
Response.Redirect "http://www.blackbeatle.com/****off.asp"
flag=false
end if
j=j+1
wend
END IF
%>
NEXT
Create a folder called: include
Within this create a txt file called: ipbanlist.inc
and in it add the following:
1.2.3.4-1.2.3.8
123.123.123.123-789.789.789.789
1.123.2.123-2.456.7.890
1.1.1.1-1.1.1.1
NEXT
Instructions for adding it to your forum files are as follows:
quote:
######################################### NOTES ##########################################################
Currently there is no niffty interface for adding IP's to a table in the DB, because I'm to lazy to create it....
So if someone would like to develop it and help the community, please do so.
######################################### Directions ######################################################
1. Copy the "IPblock.asp" file to the main forum directory
2. Copy "ipbanlist.inc" to the "Include" directory just off the main forum directory.
3. In the "inc_header.asp" file add the following 1 line near the top.
******************* THIS *************************
<!--#INCLUDE FILE="inc_func_common.asp" -->
************** To Look Like THIS *****************
<!--#INCLUDE FILE="inc_func_common.asp" -->
<!--#INCLUDE FILE="IPblock.asp" -->
4. Modify the ipbanlist.inc file to include the IP's that you wish to ban. The document can not contain any blank lines and must be in "x.x.x.x-x.x.x.x" style format on each line.
EXAMPLES:
This would ban any ip between 123.123.2.789 and 123.123.2.795 ----> 123.123.2.789-123.123.2.795
This would ban the single 123.123.456.789 IP ----> 123.123.456.789-123.123.456.789
Thats It !
Sorry it's so plain, and has no interfaces, but it's worked wonderfuly and easliy for me.
I hope this helps
Dave