shell脚本自动拉黑ssh登录失败3次以上的IP
2016-07-20 20:38
921 查看
#!/bin/bash
#Created By T.Sweet
iptables_file=/etc/sysconfig/iptables #防火墙配置文件
IP_ADDR=`tail -n 500 /var/log/secure | grep "Failed password" | awk '{print $11}' | uniq -c | awk '$1>= 3{print $2}'`
#取出登录错误3次以上的IP
cat $iptables_file | grep $IP_ADDR > /dev/null
if [ $? -ne 0 ];then
sed -i "/lo/a -A INPUT -s $IP_ADDR -p tcp --dport 22 -j DROP" $iptables_file
/etc/init.d/iptables restart
else
echo "This ip has already Deny"
fi
练习写着玩 。。。。。
本文出自 “自强不息 厚德载物” 博客,谢绝转载!
#Created By T.Sweet
iptables_file=/etc/sysconfig/iptables #防火墙配置文件
IP_ADDR=`tail -n 500 /var/log/secure | grep "Failed password" | awk '{print $11}' | uniq -c | awk '$1>= 3{print $2}'`
#取出登录错误3次以上的IP
cat $iptables_file | grep $IP_ADDR > /dev/null
if [ $? -ne 0 ];then
sed -i "/lo/a -A INPUT -s $IP_ADDR -p tcp --dport 22 -j DROP" $iptables_file
/etc/init.d/iptables restart
else
echo "This ip has already Deny"
fi
练习写着玩 。。。。。
本文出自 “自强不息 厚德载物” 博客,谢绝转载!
相关文章推荐
- shell脚本 - 检测mysql是否可用
- 用shell的方式手撕mysql僵尸连接
- shell脚本 - 完成商品销量排行的统计:倒插数据库法
- Linux知识:/root/.bashrc与/etc/profile的异同
- Jmeter BeanShell 时间格式化处理
- 73条日常Linux shell命令汇总
- makefile中的shell编程注意点
- Shell脚本一键安装LNMP环境
- Shell 中的中括号用法
- powershell 批量查询导出 组织内OU
- 关于PowerShell脚本执行时,提示服务器不愿意处理该请求
- shell脚本异常“bash: ./rebuild.sh: /bin/sh^M: bad interpreter: No such file or directory”
- PowerShell提示,因为此系统中禁止执行脚本
- linux shell编程入门笔记
- powershell
- Shell脚本编程与文件系统修复
- shell脚本练习(三)
- hdu 5730 Shell Necklace(2016多校第一场)FFT+分治
- shell的一些符号
- 用户home目录中的.bashrc的用法