推薦的用Asp實現(xiàn)屏蔽IP地址訪問的代碼
2024-05-04 11:01:17
供稿:網(wǎng)友
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
'****************************************************************
'參數(shù)vBadIP:要屏蔽的IP段,IP地址集合,用|符號分隔多個IP地址(段)
'返回Bool:True用戶IP在被屏蔽范圍,F(xiàn)alse 反之
'****************************************************************
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.net做的IP訪問限制用ASP代碼實現(xiàn)對IP的訪問限制的代碼Asp下實現(xiàn)限制IP訪問的程序代碼用asp腳本實現(xiàn)限制IP訪問ADSI+ASP添加IP到IIS禁止訪問列表中記錄游客頁面訪問IP的簡易實現(xiàn)代碼 (asp.net+txt)通過ASP禁止指定IP和只允許指定IP訪問網(wǎng)站的代碼Asp限制IP訪問 阻止某一個IP段禁止訪問本站的代碼asp實現(xiàn)限制一個ip只能訪問一次的方法