如何屏蔽某地的用户访问网站    

checkip.asp
<%
if not checkIP then
response.redirect "Error.asp"
end if
function checkIP()
dim limitIPBegin,limitIPEnd,curIP,curIPNum
curIP=GetIP()
if curIP="" then
checkIP=false
exit function
end if
limitIPBegin=GetIPNum("0.0.0.0")'封锁的IP开始段
limitIPEnd  =GetIPNum("202.114.255.255")'封锁的IP结束段
curIPNum=GetIPNum(curIP)
if curIPNum>=limitIPBegin and curIPNum<=limitIPEnd then
checkIP=false
else
checkIP=true
end if
end function

function GetIPNum(IP)
dim ipa
ipa=split(IP,".")
GetIPNum = CDbl(ipa(0)) * (256 ^ 3) + CDbl(ipa(1)) * (256 ^ 2) + CDbl(ipa(2)) * 256 + CDbl(ipa(3))
end function

function GetIP()
dim IP
IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if IP="" then IP=Request.serverVariables("REMOTE_ADDR")
GetIP=IP
end function

%>
在每个文件头部加上

 

关联文档