禁止IP访问ASP代码

把以下语句加到conn.asp即可
程序代码 程序代码
Const BadIPGroup = "92.48.127.*|83.233.165.*"
If IsForbidIP(BadIPGroup) = True Then

   Response.Redirect "error.html"

    Response.End()

End If
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  



文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.