一个屏蔽 IP 的脚本

在测试可用性的时候,经常需要模拟断网。这时候用 iptables 是比较方便的。但是如果想更方便一点,不用去敲那么长的命令会更好些。于是就写了个 ban_ip 脚本。 #!/bin/bash if [[ "$EUID" != 0 ]]; then echo "should run as root" exit 1 fi action="DROP" comment="ban_ip" cmd="$1" case "$cmd" in list) iptables -L -n | awk -v "cmt=$comment" '$0~cmt{print $4}' ;; add) ip="$2" if [[ -z "$ip" ]]; then echo "missing arg ip" exit 1 fi iptables -A […]

文章来源:

Author:神仙
link:http://xiezhenye.com/2017/06/一个屏蔽-ip-的脚本.html