php shell ddos,shell防ddos攻击脚本(一)

最近服务器经常受到攻击,并且还大多数是晚上,实在是受不了晚上起来处理,直接从网上搜了个写得不错的shell封ddos脚本,这个脚本是老外写的,我觉得效果还不错,发给大家看看吧.

系统:centos 5.9 64位

脚本内容:

vi ipdrop.sh

#!/bin/bash

#Collecting list of ip addresses connected to port 80

netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1 > /root/iplist

#Limit the no of connections

LIMIT=100;

for ip in `cat /root/iplist |awk '{print $2}'`;do

if [ `grep $ip /root/iplist | awk '{print $1}'` -gt $LIMIT ]

then

echo "100 connection from $ip... `grep $ip /root/iplist | awk '{print $1}'` number of connections... Blocking $ip";

#Blocking the ip ...

/etc/rc.d/init.d/iptables save > /dev/null;

CHECK_IF_LOCALIP=0;

/sbin/ifconfig | grep $ip > /dev/null;

if [ $? -ne $CHECK_IF_LOCALIP ]

then

{

FLAG=0;

grep $ip /etc/sysconfig/iptables | grep DROP > /dev/null;

if [ $? -ne $FLAG ]

then

iptables -I INPUT -s $ip -j DROP;

else

echo " Ipaddress $ip is already blocked ";

fi

}

else

echo " Sorry, the ip $ip cannot be blocked since this is a local ip of the server ";

fi

fi

done

夜空- 本站版权

1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权

2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意

3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责

4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

5、原文链接:blog.slogra.com/post-386.html

post-386.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值