如何在ASP里限制IP访问后台

如何在ASP里限制IP访问后台,第1张

<%= Request.ServerVariables("REMOTE_ADDR") %>客户端的IP,

再跟据这个地址判断。如果这个地址等于记录集中你数据库的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

%>


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/44945.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-02-23
下一篇2023-02-23

发表评论

登录后才能评论

评论列表(0条)

    保存