码迷,mamicode.com
首页 > 系统相关 > 详细

shell---登录失败的IP添加到/etc/hosts.deny

时间:2016-01-11 01:38:23      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:每天一个shell

/etc/hosts.deny:俗称黑名单,控制远程访问设置。

#!/bin/bash           //程序开始
#File: hosts_deny.sh
#Date: 2016-01-10

grep ‘Failed password‘ /var/log/secure | awk ‘{print $11}‘ | uniq -c | sort | //取出日志中登录失败的IP并统计排序

while read a b     //读取统计结果
do
    grep -q $b /etc/hosts.deny     //测试IP是否存在,存在为0
      if [ $? != 0 ] ; then
        if [ $a -ge 5 ] ; then   //统计的次数大于等于5
            echo "sshd: $b" >> /etc/hosts.deny    //添加IP到黑名单
            fi
      fi
done               //程序结束






本文出自 “经验来自痛苦” 博客,谢绝转载!

shell---登录失败的IP添加到/etc/hosts.deny

标签:每天一个shell

原文地址:http://strike.blog.51cto.com/10311680/1733578

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