0514-86177077
9:00-17:00(工作日)
思路:主要利用 awk ,if結(jié)構(gòu),sort,uniq
#!/bin/bash FilePath="access.log" awk '{print $1}' $FilePath | sort -rn | uniq -c >ip_count.log cat ip_count.log | while read text ####讀取文件內(nèi)容,以行為單位 do echo $text count=`echo $text | awk '{print $1}' ` ip=`echo $text | awk '{print $2}'` if [ $count -gt 20 ] then if iptables -L | grep $ip ###判斷是否已經(jīng)在iptables 中 then echo "ip地址存在iptables中,不添加 " else echo "添加ip地址到iptables" iptables -A INPUT -s $ip -j DROP echo $ip >>ip_drop.log /etc/init.d/iptables save > /dev/null ###使iptables 生效 /etc/init.d/iptables restart > /dev/null fi else echo "未到達標準,不添加到iptables" fi done
最后,我們可以把腳本添加到定時任務(wù)(crontab)里去,定時執(zhí)行,這樣就可以實現(xiàn)動態(tài)添加了。
以上所述是小編給大家介紹的利用Shell 腳本解決DDOS攻擊問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
標簽:贛州 九江 亳州 北京 懷化 河南 新疆 惠州
上一篇:shell通過遍歷輸出兩個日期范圍內(nèi)所有日期的方法
下一篇:Shell腳本經(jīng)典之Fork炸彈的分析與預(yù)防
Copyright ? 1999-2012 誠信 合法 規(guī)范的巨人網(wǎng)絡(luò)通訊始建于2005年
蘇ICP備15040257號-8