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

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

内容摘要:当我们不想让某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 
%>


标签:ip,限制,过滤
0
投稿

猜你喜欢

  • asp当中判断函数一览

    2010-05-27 12:15:00
  • 网站开发防止中文乱码需要了解的codepage的重要性小结

    2011-03-03 11:24:00
  • PHP读取和写入CSV文件的示例代码

    2023-05-24 23:54:02
  • asp查询xml的代码 不刷新页面查询的方法

    2011-04-06 11:00:00
  • Javascript 小游戏,“是男人坚持 100 次”

    2009-01-22 14:25:00
  • 解析ASP与SQL server互操作的时间处理

    2008-05-17 11:57:00
  • 细化解析:SQL Server 2000 的各种版本

    2009-02-05 15:41:00
  • AJAX无刷新验证用户名是否存在

    2007-08-10 10:07:00
  • DreamWeaver制作会移动的广告条

    2008-02-03 11:34:00
  • 关于H1的用法探讨

    2008-03-18 12:55:00
  • MySQL Dump/Restore

    2010-10-14 13:49:00
  • AJAX中文乱码解决

    2009-07-03 13:43:00
  • 超半数中文网页一年内将“消失”

    2008-03-08 12:49:00
  • ASP+ajax注册即时提示程序代码

    2011-02-05 11:25:00
  • 无忧 月影出书啦《JavaScript王者归来》

    2008-01-09 13:45:00
  • escape解决AJAX中文乱码的简单方法

    2008-10-23 14:32:00
  • IIS出现Active Server Pages错误“ASP 0201”的修复工具

    2009-05-25 18:06:00
  • 2009年情人节网站logo欣赏

    2009-02-15 12:13:00
  • Dreamweaver使用快技法十三则总结

    2008-05-01 17:32:00
  • MySQL优化之数据表的处理

    2008-12-22 14:45:00
  • asp之家 网络编程 m.aspxhome.com