#!/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
恶意登录ip添加到防火墙
原创Anonymous123 博主文章分类:shell脚本 ©著作权
©著作权归作者所有:来自51CTO博客作者Anonymous123的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:SecureCRT公钥登陆配置
下一篇:监控报警脚本
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Linux防火墙
Linux防火墙
Linux运维 iptables firewall firewalld -
自动将恶意IP加入防火墙列表脚本
自动将恶意IP加入防火墙列表脚本
恶意IP加入防火墙 -
防火墙登录方式
防火墙登录方式
华为防火墙 安全 网络