Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10626
  • 博文数量: 5
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2016-01-07 14:37
个人简介

个人是个linux菜鸟 希望大家多多交流吧

文章分类
文章存档

2016年(5)

我的朋友
最近访客

分类: 系统运维

2016-06-21 16:59:51


点击(此处)折叠或打开

  1. #!/bin/bash
  2. #by authoures lihc 2016
  3. #The script is do deny Warning IP


  4. tail -n 2000 /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/deny_IP.txt
  5. hosts_file=/etc/hosts.deny
  6. echo "########Welcome used auto_deny_ip.sh#######"
  7. echo "###########################################"
  8. echo "###########################################"
  9. echo "###########################################"
  10. DEFINE="5"

  11. cd /root ;rm -rf hosts.deny.old
  12. cp $hosts_file /root/hosts.deny.old



  13. for i in `cat /root/deny_IP.txt`
  14. do

  15. IP=`echo $i |awk -F= '{print $1}'`
  16. NUM=`echo $i|awk -F= '{print $2}'`

  17. if [ $NUM -ge $DEFINE ]; then
  18.         grep $IP /etc/hosts.deny > /dev/null

  19. if [ $? -gt 0 ]; then
  20.         echo "sshd:$IP" >> /etc/hosts.deny
  21. fi

  22. fi

  23. done
  24. #rm -rf /root/deny_IP.txt

  25. if [ $? -ge 0 ];then
  26.         echo "The script is ok"
  27. else
  28.         echo "The script is error ,please check..."
  29. fi
阅读(1013) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~