當前位置:首頁 » 密碼管理 » 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
%>

熱點內容
linux查看ftp日誌 發布:2024-11-30 06:33:19 瀏覽:474
設置截屏存儲 發布:2024-11-30 06:29:00 瀏覽:393
jpg演算法 發布:2024-11-30 06:28:55 瀏覽:194
怎麼刪除u盤中的文件夾 發布:2024-11-30 06:28:20 瀏覽:215
iphone文件夾打開 發布:2024-11-30 06:13:43 瀏覽:297
如何配置Javaweb環境 發布:2024-11-30 06:09:24 瀏覽:120
怎麼使用Androidapi 發布:2024-11-30 06:08:43 瀏覽:60
包鋼伺服器地址 發布:2024-11-30 06:06:27 瀏覽:562
繁體壓縮 發布:2024-11-30 06:06:22 瀏覽:38
osql執行sql 發布:2024-11-30 06:01:37 瀏覽:12