中文(繁体)
看了一些IP限制的函數,覺得太複雜。所以,試著寫了一個,比較簡單。請網友參考指教。謝謝! ~
代碼拷貝框<% '取得訪客的位址ip=Request.ServerVariables("REMOTE_ADDR") '允許的IP位址段為10.0.0.0~10.68.63.255 allowip1="10.0.0.0" allowip2="10.68.10.71" response. (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 "IP位址段出錯!" 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)) 或 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 %>