偶尔会有一些很令人讨厌的人访问你的网站,没办法,封IP吧……

一个简单的封少量IP的ASP代码:

<%
Dim IP,IPString,VisitIP
‘要禁止的IP地址
IPString=”|219.142.118.71|127.0.0.1|”
‘获取IP地址
IP = Request.ServerVariables(“HTTP_X_FORWARDED_FOR”)
If IP = “” Then
IP = Request.ServerVariables(“REMOTE_ADDR”)
End If
VisitIP=”|”&IP&”|”
If instr(1,IPString,VisitIP)>0 Then
response.write “你的IP被禁止”
response.end
End If
response.Write(“你的IP:”&IP&”可以访问本站”)
%>

[#afdream.com#]
禁止某个IP段访问:

<%
Dim IP,forbidIP1,forbidIP2,isForbid
”获取访问者的地址
IP = Request.ServerVariables(“HTTP_X_FORWARDED_FOR”)
If IP = “” Then
IP = Request.ServerVariables(“REMOTE_ADDR”)
End If

”禁止的IP地址段为220.191.0.0~220.191.255.255
forbidIP1=”220.191.0.0″
forbidIP2=”220.191.255.255″
isForbid=CheckIP(IP,forbidIP1,forbidIP2)
If isForbid=true Then
response.Write(“禁止访问!”)
response.End()
End IF
Response.Write(IP)

Function CheckIP(IP,forbidIP1,forbidIP2)
Dim IPString,forbid1,forbid2,forbid
forbid=false
IPString=split(IP,”.”)
forbid1=split(forbidIP1,”.”)
forbid2=split(forbidIP2,”.”)
If cint(IPString(0))>cint(forbid1(0)) And cint(IPString(0)) forbid=true
ElseIF cint(IPString(1))>cint(forbid1(1)) And cint(IPString(1)) forbid=true
ElseIF cint(IPString(2))>cint(forbid1(2)) And cint(IPString(2)) forbid=true
ElseIF cint(IPString(3))>=cint(forbid1(3)) And cint(IPString(3))<=cint(forbid2(3)) Then
forbid=true
End IF
End Function
%>

2 Comments

  1. 这段VB语法编写的代码直接include到用JScript编写的系统里面还是有点问题啊,譬如说LBS
    能给个解决办法么?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.