脚本:自动封IP

脚本:自动封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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值