看了一些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> %>