|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#!/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
|
本文转自 Anonymous123 51CTO博客,原文链接:http://blog.51cto.com/woshitieren/1681716