码迷,mamicode.com
首页 > 其他好文 > 详细

恶意登录ip添加到防火墙

时间:2015-08-04 23:13:06      阅读:220      评论:0      收藏:0      [点我收藏+]

标签: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

恶意登录ip添加到防火墙

标签:shell

原文地址:http://woshitieren.blog.51cto.com/2466034/1681716

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!