网络编程
位置:首页>> 网络编程>> Asp编程>> asp中如何对ip段进行过滤限制

asp中如何对ip段进行过滤限制

  发布时间:2007-09-17 11:14:00 

标签:ip,限制,过滤

内容摘要:当我们不想让某IP服务我们的网站时,我们就要写段程序来限制IP地址。asp中如何对ip进行过滤限制?本文介绍了一种方法,这个函数只能限制某IP段,无法限制单独的IP地址,当然要限制单独的IP应该来说是很简单:基本思路就是一获取访问者的IP,二比较我们数据库中设置的限制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.write checkip(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)) or 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 
%>


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com