<%'IP屏蔽代码:
'受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。Const BadIPGroup = "123.123.*.*|118.73.47.*"If IsForbidIP(BadIPGroup) = True Then'Response.Write(GetIP &"IP地址禁止访问")Response.Write "<script>alert('["&GetIP&"]:这里不欢迎你,你去火星吧!');this.location.href='http:///';</SCRIPT>"Response.EndEnd If'****************************************************************'参数vBadIP:要屏蔽的IP段,IP地址集合,用|符号分隔多个IP地址(段)'返回Bool:True用户IP在被屏蔽范围,False 反之'****************************************************************Function IsForbidIP(vBadIP)Dim counter, arrIPPart, arrBadIP, arrBadIPPart, i,jarrBadIP=split(vBadIP,"|")arrIPPart = Split(GetIP(), ".")For i = 0 To UBound(arrBadIP)counter = 0arrBadIPPart = Split(arrBadIP(i), ".")For j = 0 To UBound(arrIPPart)If(arrBadIPPart(j)) = "*" or Cstr(arrIPPart(j))=Cstr(arrBadIPPart(j)) Thencounter = counter + 1End IfNextIf counter=4 ThenIsForbidIP=TrueExit FunctionEND IFNextIsForbidIP = FalseEnd Function
'***************'返回客户IP地址'***************Function GetIP()dim ipIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR")GetIP = IPEnd Function%>