以下(xià)是引用片段:
可單獨放(fàng)置在某個頁面或獨立成一(yī)個文件進行調用
<% '受屏蔽IP地址(段)集合,星号爲通配符,通常保存于配置文件中(zhōng)。 Const BadIPGroup = "94.142.131.20|124.225.74.51|192.168.0.*|59.26.284.*"
If IsForbidIP(BadIPGroup) = True Then Response.Write(GetIP &"系統已記錄您的IP地址信息") Response.Write("<BR>") Response.Write("由于您在本站發布大(dà)量垃圾信息!管理員(yuán)已禁止您訪問站點。") Response.Write("<BR>") Response.Write("需要開(kāi)通請聯系") Response.End() End If
'參數vBadIP:要屏蔽的IP段,IP地址集合,用|符号分(fēn)隔多個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 %>
|