相思资源网 Design By www.200059.com
By zkxp 2/15/2006 http://zkxp.cnblogs.com
‘受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。
<%
Const BadIPGroup = "220.200.59.136|220.205.168.141"
If IsForbidIP(BadIPGroup) = True Then
Response.Write(GetUserIP &"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(GetUserIP(), ".")
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 GetUserIP()
Dim IP
IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR")
GetUserIP = IP
End Function
%>
‘受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。
<%
Const BadIPGroup = "220.200.59.136|220.205.168.141"
If IsForbidIP(BadIPGroup) = True Then
Response.Write(GetUserIP &"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(GetUserIP(), ".")
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 GetUserIP()
Dim IP
IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IP = "" Then IP = Request.ServerVariables("REMOTE_ADDR")
GetUserIP = IP
End Function
%>
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无推荐的用Asp实现屏蔽IP地址访问的代码的评论...