看了一些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> %>
【asp中对ip进行过滤限制函数】相关文章: