屏蔽ip段访问 html,限制某IP段对网页的访问(ASP)
ASP腳本限制某IP段對網頁的訪問
昨天為了做個測試,要對某段IP做限制訪問我的網頁,于是上網搜了些代碼,我做了下調整,分享給大家。我找到了兩種方法,上代碼:
方法一:
限制IP段訪問function IP2Num(sip)
dim str1,str2,str3,str4
dim num
IP2Num=0
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)
num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)
IP2Num = num
end if
end function
function Num2IP(nip)
iip1 = int(nip/256/256/256)
iip2 = int((nip-iip1*256*256*256)/256/256)
iip3 = int((nip-iip1*256*256*256-iip2*256*256)/256)
iip4 = int((nip-iip1*256*256*256-iip2*256*256-iip3*256) mod 256)
iip0 = iip1 &"."& iip2 & "." &iip3 &"."& iip4
Num2IP = iip0
end function
userIPnum = IP2Num(Request.ServerVariables("REMOTE_ADDR"))
if userIPnum > IP2Num("192.168.150.0") and userIPnum < IP2Num("192.168.150.138") then
response.write ("
您的IP被禁止")response.end
else response.write ("
您的IP被未被限制!")end if
%>
方法二:
限制IP段訪問——2'限制192.168.150.130(3232274049)到192.168.150.140(3232274059)
ip=request.servervariables("remote_addr")
sip=split(ip,".")
num=cint(sip(0))*256*256*256+cint(sip(1))*256*256+cint(sip(2))*256+cint(sip(3))-1
response.write(ip)
response.write("
")
if (num >= 3232274049 and num <= 3232274059) then
response.write("您的ip被限制!")
response.End()
else
response.write("您的ip未被禁止")
end if
%>
總結:
以上兩種方法都是針對ASP腳本,其他腳本的限制方法跟其類似。
總結
以上是生活随笔為你收集整理的屏蔽ip段访问 html,限制某IP段对网页的访问(ASP)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 西北师大与新华三开展物联网战略合作,共建
- 下一篇: 服务器响应程序,封装高可复用的服务端响应