简单shell脚本

简单的使用shell实现增加一条防火墙规则!
#!/bin/bash
if [ $# -ne 2 ];then
        echo "Please Use: $0 ip port"
        exit
fi

regx="((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)\.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)"
ip=$1
str=`echo $1|egrep ^"$regx"$`
if [ -z $str ]; then
        echo "Invalid IP!"
        exit
fi
port=$2
iptables -A INPUT -s $ip -p tcp --dport $2 -j ACCEPT
echo succed

你可能感兴趣的:(简单shell脚本)