Chinaunix首页 | 论坛 | 博客
  • 博客访问: 290731
  • 博文数量: 49
  • 博客积分: 4776
  • 博客等级: 中校
  • 技术积分: 486
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-02 10:42
文章分类

全部博文(49)

文章存档

2010年(6)

2009年(8)

2008年(20)

2007年(10)

2006年(2)

2005年(3)

分类:

2009-12-18 12:16:40

脚本:自动封IP
 
#!/bin/bash
limit="6"
zero="0"
num=`tail -100  ar/log cure |grep "Failed password for invalid user" |awk '{print $13}' |sort |uniq -c`
echo "$num" > /tmp mit.txt
sed -i '/sshd/d' /etc/hosts.deny
while read line
do
times=`echo "$line" |awk '{print $1}'`
ipadd=`echo "$line" |awk '{print $2}'`
if [ $times > $limit ] ; then
echo sshd:$ipadd >> /etc/hosts.deny
fi
done < /tmp/limit.txt
 
user=`cat /etc/passwd |cut -d: -f1`
for i in $user
do
checkF=`tail -100  ar/log cure |grep "Failed password for $i from" |awk '{print $11}' |sort |uniq -c`
echo "$checkF"|grep -v "^$" > /tmp/limit.txt
while read line
do
num=`echo "$line" |awk '{print $1}'`
mac=`echo "$line" |awk '{print $2}'`
if [ $num -gt $limit ] ; then
exist=`sed -n '/'$mac'/p' /etc/hosts.deny|wc -l`
if [ $exist -eq $zero ] ; then
echo sshd:$mac >> /etc/hosts.deny
fi
fi
done < /tmp/limit.txt
done
阅读(2020) | 评论(1) | 转发(0) |
0

上一篇:VsFTP相关

下一篇:IT终极监控

给主人留下些什么吧!~~

chinaunix网友2009-12-22 15:27:39

dfgdgdf