WEBSITECOPNFIG为表名,IPLIST为定义禁止访问的IP地址列表
在需要禁止的页面获取来访者的IP地址visitedIP=request.servervariables("REMOTE_ADDR")
如果IPLIST包含VISITEDIP,则禁止访问,具体实现方法如下:
<%
visitedIP=request.servervariables("REMOTE_ADDR")
....连接数据库,略
....读取WEBSITECONFIG表,略
if instr(IPLIST,visitedIP)>0 then
response.write "你的IP地址被禁止访问本站"
response.end
end if
%>
首先要建立一个IP黑名单,页面打开前获取访问者IP地址,通过IP地址比对,是否输出页面下面的函数是获取访问者IP
' ============================================
' 获取访问者IP地址
' ============================================
Function GetUserTrueIP()
dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") >0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") >0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "") >0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
GetUserTrueIP = Trim(Mid(strIPAddr, 1, 30))
End Function
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)