当前位置:首页 » 密码管理 » 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
%>

热点内容
怎么看pppoe密码 发布:2024-11-30 08:35:35 浏览:509
sandisk16gb存储卡 发布:2024-11-30 08:34:42 浏览:953
eclipsejava反编译 发布:2024-11-30 08:34:37 浏览:899
yy静态头像源码 发布:2024-11-30 08:30:21 浏览:680
javaparseint 发布:2024-11-30 08:23:12 浏览:909
抖音密码箱保险在哪里 发布:2024-11-30 08:10:43 浏览:998
广告文学脚本格式 发布:2024-11-30 08:09:57 浏览:634
期末到了解压的方法 发布:2024-11-30 07:53:49 浏览:865
sqlce数据库 发布:2024-11-30 07:41:21 浏览:726
奇瑞5x配置如何 发布:2024-11-30 07:39:50 浏览:642