asp 批量屏蔽ip代碼

來源:互聯網
上載者:User

<%
'IP屏蔽代碼:www.goudiannao.com

'受屏蔽IP地址(段)集合,星號為萬用字元,通常儲存於設定檔中。
Const BadIPGroup = "123.123.*.*|118.73.47.*"
If IsForbidIP(BadIPGroup) = True Then
'Response.Write(GetIP &"IP地址禁止訪問")
Response.Write "<script>alert('["&GetIP&"]:這裡不歡迎你,你去火星吧!');this.location.href='http://http://www.goudiannao.com//';</SCRIPT>"
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
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.