Linux防护CC攻击bash脚本

没事学习学习,早上看了别人防止CC攻击的shell脚本,代码的风格跟自己有点不一样,而且感觉大部分博客都是你抄我,我抄你的,里面缺少些东西,例如echo到文本,那个文本根本就不存在,也没有创建的操作,而且使用的sendmail发的,我这本地没搞定sendmail,用的mailx来发邮件,重写的脚本如下:

#!/bin/bash
#author merci

iplist=`netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"[ ]+|[:]" '{print $6}'|sort|uniq -c|sort -rn| awk '$1>20'`
if [ ! -f 'denyip.log' ]
then
    touch denyip.log
fi
if [[ ! -z $iplist ]]
then
	for denyip in $iplist
	do	
		denyiplist=`iptables -nL | grep $denyip`
		if [[ -z $denyiplist ]]
		then
			iptables -I INPUT -s $denyip -j DROP & echo 1 > denyip.log
		fi
	done
	if [[ `cat denyip.log` ] == 1 ]
	then
		echo -e 'DenyIp list\n $iplist' | mailx -s 'DenyIp list' shevechco@qq.com
		rm -rf denyip.log >/dev/null 2>&1
	fi
fi


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/503.html

我要评论

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