限制IP访问

后浪 2010-06-10 03:52:39
今天发现公司网站频繁被某IP访问!
我想实现不管哪个IP访问,任何时间段,超过 20次/分,就不让它访问了
哪位大侠帮我写个,感激不禁,泪流满面!
...全文
155 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
猜我是几娃 2010-06-12
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 xiaoye_loison 的回复:]
同一页面,一天被刷了20W次
[/Quote]

有这样的情况,那肯定不可能是人工操作的了,所以用cookies做限制应该是不错的选择。
第一、不需要访问数据库,提高了执行效率。
第二、也不存在对正常用户不友好的情况,因为加了时间间隔控制。如果刷网页的人还能想到去清空下cookies的话,一天能刷20万次嘛。。。

不过如果你的网站是被人家ddos了。。。那就什么办法都回天无力了
greenoldman 2010-06-12
  • 打赏
  • 举报
回复
问题出现,我个人觉得,解决的思路可以再斟酌下。 我打开20个请求后,就不让我访问了,这个对网站没有好处,防火墙是可以阻挡些垃圾访问,如果有条件应该有。 可以分析访问日志,手动将 不让访问的IP给屏蔽了。毕竟这只是少数,如果是庞大的IP量,恭喜你,你的网站很成功了!
zhuxibang 2010-06-12
  • 打赏
  • 举报
回复
防火墙有现成的功能, 同一ip超过每秒多少次访问就阻止在外,压力都在硬件防火墙那(好的防火墙可支持每秒几十万次的并发),压不倒你网站这边来,如果在网站这边实现不管你怎么组织,人家还是照样能访问
Pluto离为火 2010-06-12
  • 打赏
  • 举报
回复
9楼强
后浪 2010-06-12
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 chinmo 的回复:]
不知道你要做什么,频繁访问是同一个页面还是不同页面的呢?
不同页面很正常啊
[/Quote]
同一页面,一天被刷了20W次
lfywy 2010-06-12
  • 打赏
  • 举报
回复
cookie也不是最好的办法,因为别人可以自己清空cookie啊
猜我是几娃 2010-06-11
  • 打赏
  • 举报
回复
修改了下,加强版:

<%
if request.Cookies("AccTimes")="" then
response.Cookies("AccTimes")=0
response.Cookies("LastTime")=now()
response.Cookies("Forbidden")="false" '设置一 个是否能访问的标志,初始是能访问的
else
AccTimes=request.Cookies("AccTimes")
LastTime=request.Cookies("LastTime")
end if
if request.Cookies("Forbidden")="false" then
if not (LastTime="" or LastTime=Empty or AccTimes="" or AccTimes=Empty) then
if datediff("n",LastTime,now()) >= 0 and datediff("n",LastTime,now()) < 1 then '记录1分钟以内的访问次数
if AccTimes < 20 then ' 20次以内,则次数累加
AccTimes = AccTimes + 1
response.Cookies("AccTimes") = AccTimes
else '超过20次,禁止访问
response.Write "Forbidden!"
response.Cookies("Forbidden")="true" '给访问标志赋值,以后都不让访问
response.End()
end if
response.Write AccTimes&"<br>" '测试用,可以删掉
else ' 对于在1分钟之内没有超过20次访问的情况,须将时间和次数都重新设置
response.Cookies("LastTime")=now()
response.Cookies("AccTimes")=0
end if
end if
elseif request.Cookies("Forbidden")="true" then
response.Write "Forbidden!"
response.End()
end if
%>
猜我是几娃 2010-06-11
  • 打赏
  • 举报
回复
用cookies 是最方便,效率也是比较高的方法,楼上的方法没有考虑到还有时间间隔这个因素。
抛砖引玉。。。

<%
if request.Cookies("AccTimes")="" then
response.Cookies("AccTimes")=0
response.Cookies("LastTime")=now()
else
AccTimes=request.Cookies("AccTimes")
LastTime=request.Cookies("LastTime")
end if
if not (LastTime="" or LastTime=Empty or AccTimes="" or AccTimes=Empty) then
if datediff("n",LastTime,now()) >= 0 and datediff("n",LastTime,now()) < 1 then '记录1分钟以内的访问次数
if AccTimes < 20 then ' 20次以内,则次数累加
AccTimes = AccTimes + 1
response.Cookies("AccTimes") = AccTimes
else '超过20次,禁止访问
response.Write "Forbidden!"
response.End()
end if
response.Write AccTimes&"<br>" '测试用,可以删掉
else ' 对于在1分钟之内没有超过20次访问的情况,须将时间和次数都重新设置
response.Cookies("LastTime")=now()
response.Cookies("AccTimes")=0
end if
end if
%>
in0512 2010-06-11
  • 打赏
  • 举报
回复

<%utimes=clng(request.Cookies("utimes"))
if utimes="" or isnull(utimes) then
response.Cookies("utimes")=1
response.cookies("utimes").expires=date +365 'cookies有效天数
else
response.Cookies("utimes")=utimes+1
if utimes+1>20 then
response.Write "禁止访问"
response.end
end if
end if
%>


用cookies吧.
line_us 2010-06-11
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 buker19999 的回复:]
修改了下,加强版:

VBScript code

<%
if request.Cookies("AccTimes")="" then
response.Cookies("AccTimes")=0
response.Cookies("LastTime")=now()
response.Cookies("Forbidden")="false" '设置一 个是否能……
[/Quote]
支持
后浪 2010-06-11
  • 打赏
  • 举报
回复
没人帮忙吗!自己顶
  • 打赏
  • 举报
回复
不知道你要做什么,频繁访问是同一个页面还是不同页面的呢?
不同页面很正常啊
sjz123426 2010-06-11
  • 打赏
  • 举报
回复
楼上的正解。。。
zhuxibang 2010-06-11
  • 打赏
  • 举报
回复
防火墙层次需要设置
后浪 2010-06-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yifanwu 的回复:]
后台搞个数据库,记下IP和访问时间,下次有人访问的时候做个对比,查询一下1个IP在10分钟内是否访问了20次,是就封!
[/Quote]
效率太低了吧...
后浪 2010-06-10
  • 打赏
  • 举报
回复
1楼的看了,没用。继续等待...


LANMIN 2010-06-10
  • 打赏
  • 举报
回复
楼主太搞笑了

你可以试下1楼的方法!
yifanwu 2010-06-10
  • 打赏
  • 举报
回复
后台搞个数据库,记下IP和访问时间,下次有人访问的时候做个对比,查询一下1个IP在10分钟内是否访问了20次,是就封!
mino_0000 2010-06-10
  • 打赏
  • 举报
回复
这里有个可以作为参考..


<%
ip=Request.ServerVariables("REMOTE_ADDR")
fileurl="http://www.ip138.com/ips.asp?ip="&ip
dotloc=InStrRev(fileurl,".")
filepath="thistest"&mid(fileurl,dotloc)


call saveRemoteFile(filepath,fileurl)

sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
dim Ads,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody

End With

Set Retrieval = Nothing


Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set Ads=nothing
end sub


set fso=server.createobject("scripting.filesystemobject")
set fileout=fso.opentextfile(server.mappath(filepath),1)
content=fileout.readall
set fileout=nothing
set fso=nothing


if ubound(split(content,"南通"))>1 then
response.Write("您不允许访问我们的网站")
response.end
elseif ubound(split(content,"如皋"))>1 then
response.Write("您不允许访问我们的网站")
response.end
elseif ubound(split(content,"海安"))>1 then
response.Write("您不允许访问我们的网站")
response.end
elseif ubound(split(content,"启东"))>1 then
response.Write("您不允许访问我们的网站")
response.end
elseif ubound(split(content,"如东"))>1 then
response.Write("您不允许访问我们的网站")
response.end
elseif ubound(split(content,"海门"))>1 then
response.Write("您不允许访问我们的网站")
response.end
elseif ubound(split(content,"通州"))>1 then
response.Write("您不允许访问我们的网站")
response.end
else
response.Write("Hello 您好")
end if
%>



28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧