推荐的用Asp实现屏蔽IP地址访问的代码

所属分类: 网络编程 / ASP编程 阅读数: 770
收藏 0 赞 0 分享
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
%>
更多精彩内容其他人还在看

asp中去除内容HTML标签的三个function函数

asp中去除内容HTML标签的三个function函数
收藏 0 赞 0 分享

chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解

chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解
收藏 0 赞 0 分享

方便的大家admin及admin888 经过 md5加密后16位和32位代码

方便的大家admin及admin888 经过 md5加密后16位和32位代码
收藏 0 赞 0 分享

可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集

可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集
收藏 0 赞 0 分享

asp动态级联菜单代码

asp动态级联菜单代码
收藏 0 赞 0 分享

ASP中经常使用的SQL语句与教程说明

ASP中经常使用的SQL语句与教程说明
收藏 0 赞 0 分享

实例分析之用ASP编程实现网络内容快速查找的代码

实例分析之用ASP编程实现网络内容快速查找的代码
收藏 0 赞 0 分享

服务端 VBScript 与 JScript 几个相同特性的写法与示例

服务端 VBScript 与 JScript 几个相同特性的写法与示例
收藏 0 赞 0 分享

ASP 环境下 VBS 事件应用 示例代码

ASP 环境下 VBS 事件应用 示例代码
收藏 0 赞 0 分享

asp 之上传漏洞终结篇

asp 之上传漏洞终结篇
收藏 0 赞 0 分享
查看更多