标签:shell
#!/bin/bash #by lijq LOG=/var/log/secure IPTABLE_FILE=/etc/sysconfig/iptables LOG_IP=`grep "Failed password" /var/log/secure | awk ‘{print $11}‘ |uniq -c |awk ‘$1>4 {print $2}‘` function add_iptables() { for i in $LOG_IP do IPTABLE_IP=`grep "$i" $IPTABLE_FILE` if [ -z $IPTABLE_IP ];then sed -i "/lo/a-A INPUT -s $i -m state --state NEW -m tcp -p tcp --dport 22 -j DROP" $IPTABLE_F ILE;/etc/init.d/iptables restart; if [ $? -eq 0 ];then echo -e "\033[32mIt is success will the ip add this file..........\033[0m" else echo -e "\033[32mIt is failed add the ip,please check.............\033[0m" fi else echo -e "\033[32mThis iptables restrictions is exist,.....\033[0m" fi done } if [ ! -z $LOG_IP ];then add_iptables else echo -e "\033[32mIt is no this BAD ip to add .....\033[0m" exit fi
本文出自 “毛毛鸭” 博客,请务必保留此出处http://woshitieren.blog.51cto.com/2466034/1681716
标签:shell
原文地址:http://woshitieren.blog.51cto.com/2466034/1681716