其他分享
首页 > 其他分享> > 半自动化多站点屏蔽恶意用户的IP(脚本)

半自动化多站点屏蔽恶意用户的IP(脚本)

作者:互联网

前瞻:
用于多站点操作,基于ansible批量化操作
前提需要安装ansible且在nginx.conf中添加如下参数
include /usr/local/nginx/conf/denyIP;
在conf下创建denyIP,将屏蔽ip写入denyIP即可屏蔽
touch denyIP
因为使用的ansible所以每个zhandian(1-6)实际上在ansible/hosts中都是包含了多个站点的

#!/bin/bash
read -p "请输入需要屏蔽的IP: " forbidip
cat << EOF
----------------------------------------
|***************站点列表***************|
----------------------------------------
`echo -e "\033[35m 1)zhandian-1\033[0m"`
`echo -e "\033[35m 2)zhandian-2\033[0m"`
`echo -e "\033[35m 3)zhandian-3\033[0m"`
`echo -e "\033[35m 4)zhandian-4\033[0m"`    
`echo -e "\033[35m 5)zhandian-5\033[0m"`
`echo -e "\033[35m 6)zhandian-6\033[0m"`
EOF
read -p "请输入需要执行的站点编号:" cmd
case $cmd in
1)
        sudo /usr/bin/ansible zhandian-1 -m shell -a "sudo sed -i  '\$a\deny ${forbidip};'  /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-1 -m shell -a "sudo systemctl restart nginx";;
2)
        sudo /usr/bin/ansible zhandian-2 -m shell -a "sudo sed -i  '\$a\deny ${forbidip};'  /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-2 -m shell -a "sudo systemctl restart nginx";;
3)
        sudo /usr/bin/ansible zhandian-3 -m shell -a "sudo sed -i  '\$a\deny ${forbidip};'  /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-3 -m shell -a "sudo systemctl restart nginx";;
4)
        sudo /usr/bin/ansible zhandian-4 -m shell -a "sudo sed -i  '\$a\deny ${forbidip};'  /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-4 -m shell -a "sudo systemctl restart nginx";;
5)
        sudo /usr/bin/ansible zhandian-5 -m shell -a "sudo sed -i  '\$a\deny ${forbidip};'  /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-5 -m shell -a "sudo systemctl restart nginx";;
6)
        sudo /usr/bin/ansible zhandian-6 -m shell -a "sudo sed -i  '\$a\deny ${forbidip};'  /usr/local/nginx/conf/denyIP" && sudo ansible zhandian-6 -m shell -a "sudo systemctl restart nginx";;
*)
        echo "errpr:please in input (1,2,3,4,5,6)";;
esac

标签:denyIP,IP,半自动化,站点,屏蔽,ansible,conf
来源: https://blog.51cto.com/13555423/2614073