'受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。
Const BadIPGroup = "192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1"
If IsForbidIP(BadIPGroup) = True Then
Response.Write(GetIP &"IP地址禁止访问")
Response.End()
End If
'参数vBadIP:要屏蔽的IP段,IP地址集合,用|符号分隔多个IP地址(段)
'返回Bool:True用户IP在被屏蔽范围,False 反之
Function IsForbidIP(vBadIP)
Dim counter, arrIPPart, arrBadIP, arrBadIPPart, i, j
arrBadIP = Split(vBadIP, "|")
arrIPPart = Split(GetIP(), ".")
For i = 0 To UBound(arrBadIP)
counter = 0
arrBadIPPart = Split(arrBadIP(i), ".")
For j = 0 To UBound(arrIPPart)
If(arrBadIPPart(j)) = "*" or Cstr(arrIPPart(j)) = Cstr(arrBadIPPart(j)) Then
counter = counter + 1
End If
Next
If counter = 4 Then
IsForbidIP = True
Exit Function
End If
Next
IsForbidIP = False
End Function
'返回客户IP地址
Function GetIP()
Dim IP
IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR")
GetIP = IP
End Function
%>
<%IP_Address = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IP_Address = "" Then
IP_Address = Request.ServerVariables("REMOTE_ADDR")
end if
%>
这样可以取到访问者的ip地址,判断一下是不是那两个ip,如果是的话就不做 *** 作,不让访问的话做个跳转
<%
response.Write"<script>alert('只对内部开放!')location.href('提示页面.asp')</script>"
%>
http://arthorzhou888.blog.163.com/blog/static/313091532007624112841640/把这个写入数据库 然后加入到conn.asp文件里面 很简单
ip=Request.ServerVariables("REMOTE_ADDR")
''允许的IP地址段为10.0.0.0~10.50.50.255
allowip1="10.0.0.0"
allowip2="10.50.10.70"
response.write checkip(ip,allowip1,allowip2)
function checkip(ip,allowip1,allowip2)
dim check(4)
checkip=false
ipstr=split(ip,".")
allow1=split(allowip1,".")
allow2=split(allowip2,".")
if cint(allow1(0))>cint(allow2(0)) then ''判断IP地址段是否合*
response.write "禁止访问"
exit function
end if
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)