asp中對ip進行過濾限制函數

來源:互聯網
上載者:User

   看了一些IP限制的函數,覺得太複雜。所以,試著寫了一個,比較簡單。請網友參考指教。謝謝!~

<%<BR> '擷取訪問者的地址<BR> ip=Request.ServerVariables("REMOTE_ADDR") <BR> <BR> '允許的IP位址區段為10.0.0.0~10.68.63.255<BR> allowip1="10.0.0.0"<BR> allowip2="10.68.10.71"<BR> <BR> response.write checkip(ip,allowip1,allowip2)<BR> <BR> <BR> function checkip(ip,allowip1,allowip2)<BR> dim check(4)<BR> checkip=false<BR> ipstr=split(ip,".")<BR> allow1=split(allowip1,".")<BR> allow2=split(allowip2,".")<BR> if cint(allow1(0))>cint(allow2(0)) then '判斷IP位址區段是否合法<BR> response.write "IP位址區段出錯!"<BR> exit function<BR> end if<BR> for i=0 to ubound(ipstr)<BR> if cint(allow1(i))<cint(allow2(i)) then<BR> if cint(allow1(i))=cint(ipstr(i)) then<BR> check(i)=true<BR> checkip=true<BR> exit for<BR> else<BR> if cint(ipstr(i))<cint(allow2(i)) then<BR> check(i)=true<BR> checkip=true<BR> exit for<BR> else<BR> if cint(ipstr(i))>cint(allow2(i)) then<BR> check(i)=false<BR> checkip=false<BR> exit for<BR> else<BR> check(i)=true<BR> checkip=true<BR> end if<BR> end if<BR> end if<BR> else<BR> if cint(allow1(i))>cint(ipstr(i)) or cint(allow1(i))<cint(ipstr(i)) then<BR> check(i)=false<BR> checkip=false<BR> if i<>ubound(ipstr) then<BR> exit for<BR> end if<BR> else<BR> check(i)=true<BR> end if<BR> end if<BR> next<BR> <BR> if (check(0)=true and check(1)=true and check(2)=true and check(3)=false) and (cint(allow2(2))>cint(ipstr(2))) then<BR> checkip=true<BR> end if<BR> <BR> end function<BR> %>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.