Byzkxp2/15/2006http://zkxp.cnblogs.com
‘受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。
<%
ConstBadIPGroup="220.200.59.136|220.205.168.141"
IfIsForbidIP(BadIPGroup)=TrueThen
Response.Write(GetUserIP&"IP地址禁止访问")
Response.End()
EndIf
'****************************************************************
'参数vBadIP:要屏蔽的IP段,IP地址集合,用|符号分隔多个IP地址(段)
'返回Bool:True用户IP在被屏蔽范围,False反之
'****************************************************************
FunctionIsForbidIP(vBadIP)
Dimcounter,arrIPPart,arrBadIP,arrBadIPPart,i,j
arrBadIP=Split(vBadIP,"|")
arrIPPart=Split(GetUserIP(),".")
Fori=0ToUBound(arrBadIP)
counter=0
arrBadIPPart=Split(arrBadIP(i),".")
Forj=0ToUBound(arrIPPart)
If(arrBadIPPart(j))="*"orCstr(arrIPPart(j))=Cstr(arrBadIPPart(j))Then
counter=counter+1
EndIf
Next
Ifcounter=4Then
IsForbidIP=True
ExitFunction
EndIf
Next
IsForbidIP=False
EndFunction
'***************
'返回客户IP地址
'***************
FunctionGetUserIP()
DimIP
IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
IfIP=""ThenIP=Request.ServerVariables("REMOTE_ADDR")
GetUserIP=IP
EndFunction
%>