當前位置:首頁 » 密碼管理 » asp禁止訪問

asp禁止訪問

發布時間: 2023-09-29 13:12:33

❶ ASP限制IP訪問

1.ASP限制IP訪問代碼

<%
''獲取訪問者的地址
ip=Request.ServerVariables("REMOTE_ADDR")

''允許的IP地址段為10.0.0.0~10.50.50.255
allowip1="10.0.0.0"
allowip2="10.50.10.70"
response.write checkip(ip,allowip1,allowip2)
function checkip(ip,allowip1,allowip2)
dim check(4)
checkip=false
ipstr=split(ip,".")
allow1=split(allowip1,".")
allow2=split(allowip2,".")
if cint(allow1(0))>cint(allow2(0)) then ''判斷IP地址段是否合*
response.write "禁止訪問"
exit function
end if
for i=0 to ubound(ipstr)
if cint(allow1(i))<cint(allow2(i)) then
if cint(allow1(i))=cint(ipstr(i)) then
check(i)=true
checkip=true
exit for
else
if cint(ipstr(i))<cint(allow2(i)) then
check(i)=true
checkip=true
exit for
else
if cint(ipstr(i))>cint(allow2(i)) then
check(i)=false
checkip=false
exit for
else
check(i)=true
checkip=true
end if
end if
end if
else
if cint(allow1(i))>cint(ipstr(i)) or cint(allow1(i))<cint(ipstr(i)) then
check(i)=false
checkip=false
if i<>ubound(ipstr) then
exit for
end if
else
check(i)=true
end if
end if
next
if (check(0)=true and check(1)=true and check(2)=true and check(3)=false) and (cint(allow2(2))>cint(ipstr(2))) then
checkip=true
end if
end function
%>

2.用戶IP限制

<%'用戶IP限制
function LockIP(sip)
dim str1,str2,str3,str4
dim num
LockIP=false
if isnumeric(left(sip,2)) then
str1=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
str2=left(sip,instr(sip,".")-1)
sip=mid(sip,instr(sip,".")+1)
str3=left(sip,instr(sip,".")-1)
str4=mid(sip,instr(sip,".")+1)
if isNumeric(str1)=0 or isNumeric(str2)=0 or isNumeric(str3)=0 or isNumeric(str4)=0 then

else
num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
sql="select count(*) from LockIP where ip1 <="&num&" and ip2 >="&num&""
set rs_ip=conn.execute(sql)
if rs_ip(0)>0 then
LockIP=true
end if
set rs_ip=nothing
end if
end if
end function%>
<%if LockIP(Request.ServerVariables("REMOTE_ADDR")) then
response.write "<script>alert('您的IP:"&request.servervariables("remote_addr")&"已經被限制不能訪問,請和管理員聯系');location.href='about:blank'</script><script>window.close();</script>"
response.end
end if
%>
<%
noip=Request.Servervariables("HTTP_X_FORWARDED_FOR")
If noip="" Then noip=Request.Servervariables("REMOTE_ADDR")
set rst11=server.createobject("adodb.recordset")
sql="select * from fuck where userip='"&noip&"'"
rst11.open sql,conn,1,1
if not rst11.eof and not rst11.bof then
response.write "<script>alert('您的IP:"&request.servervariables("remote_addr")&"已經被限制不能訪問,請和管理員聯系');location.href='about:blank'</script><script>window.close();</script>"
response.end
end if
%>

❷ 修改asp限制IP訪問

參考下面的屏蔽ip段的代碼<%
'受屏蔽IP地址(段)集合,星號為通配符,通常保存於配置文件中。
ConstBadIPGroup="192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1"
IfIsForbidIP(BadIPGroup)=TrueThen
Response.Write(GetIP&"IP地址禁止訪問")
Response.End()
EndIf

'參數vBadIP:要屏蔽的IP段,IP地址集合,用|符號分隔多個IP地址(段)
'返回Bool:True用戶IP在被屏蔽范圍,False反之
FunctionIsForbidIP(vBadIP)
Dimcounter,arrIPPart,arrBadIP,arrBadIPPart,i,j
arrBadIP=Split(vBadIP,"|")
arrIPPart=Split(GetIP(),".")
Fori=0ToUBound(arrBadIP)
counter=0
arrBadIPPart=Split(arrBadIP(i),".")
Forj=0ToUBound(arrIPPart)
If(arrBadIPPart(j))="*"orCstr(arrIPPart(j))=Cstr(arrBadIPPart(j))Then
counter=counter+1
EndIf
Next
Ifcounter=4Then
IsForbidIP=True
ExitFunction
EndIf
Next
IsForbidIP=False
EndFunction
'返回客戶IP地址
FunctionGetIP()
DimIP
IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
IfIP=""ThenIP=Request.ServerVariables("REMOTE_ADDR")
GetIP=IP
EndFunction
%>

熱點內容
maven3編譯jdk6項目 發布:2024-10-07 03:19:57 瀏覽:43
緩存的視頻無法剪輯 發布:2024-10-07 03:19:40 瀏覽:88
解壓工具RAR 發布:2024-10-07 02:42:49 瀏覽:352
蘋果網盤解壓 發布:2024-10-07 02:42:49 瀏覽:159
為什麼安卓蘋果手游不互通 發布:2024-10-07 02:31:28 瀏覽:280
如何刪除手機中的游戲緩存 發布:2024-10-07 02:11:28 瀏覽:874
解鎖資料庫用戶 發布:2024-10-07 01:55:54 瀏覽:828
關系資料庫的關鍵字是指 發布:2024-10-07 01:55:54 瀏覽:518
java資料庫date 發布:2024-10-07 01:55:21 瀏覽:459
安卓12如何開通運用許可權 發布:2024-10-07 01:29:54 瀏覽:137