众果搜的博客

脚踏大地,仰望星空,致力于财经投资网站导航与在线网络工具的开发与普及

Search(博客搜索)

热文排行

最近发表

最新评论及回复

« 劳民伤财碳排放在线计算器 »

禁止指定IP地址对博客文章的访问

由于SPAM垃圾机器的泛滥,以及对博客漏洞的嗅探的升温,造成小站博客文章访问量大增,弄得存放的虚拟主机被ISP多次警告,并临时设限停机。查了查真正的网页访问量并没有上去,而是这些机器人在捣鬼。

使用WebLogExplorer查看网站日志发现几个IP地址对博客文章的访问量是普通的上百倍,是造成所在虚拟主机CPU占用率高的罪魁祸首,于是在博客文章浏览页面加入以下代码:
'加入IP地址过滤功能
      '获取访问者的地址
      Dim ip
      ip=Request.ServerVariables("REMOTE_ADDR") 
      If ip="221.15.149.61" OR ip="218.240.13.108" OR ip="124.92.235.246" OR ip="123.131.142.214" OR ip="221.218.94.231" OR ip="222.91.235.78" OR ip="123.131.254.211" OR ip="218.27.154.242"  Then
      Response.redirect("http://localhost")
     End If

如果这些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 "禁止访问"
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地址过滤功能
      '获取访问者的地址
      'Dim ip
      'ip=Request.ServerVariables("REMOTE_ADDR") 
     ' If ip="221.15.149.61" OR ip="218.240.13.108" OR ip="124.92.235.246" OR ip="123.131.142.214" OR ip="221.218.94.231" Then
      'Response.redirect("http://localhost")
     ' End If 

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense

Copyright www.zhongguosou.com. Some Rights Reserved.微信号:MiZhiHeiGeTaXiaoMi