文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>portforward.sh 练习一下

portforward.sh 练习一下

时间:2006-01-15  来源:ruiqingzheng

#!/bin/bash

if [ ! $# -eq 2 ];then
        echo "Usage:`basename $0` IP PORT" && exit 1
else
        echo $1 | grep -oq "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$"
        if [ ! $? -eq 0 ]; then
                echo "Illegal IP $1"
                exit 2
        else
                echo "Correct  IP format $1"
        fi

        echo $2 | grep -oq "[0-9]\{1,5\}$"
        if [ ! $? -eq 0 ]; then
                echo "Illegal PORT $2"
                exit 3
        else
                echo "Correct PORT format $2"
        fi
fi
IP=$1
PORT=$2

# set all rules default if you want
read -p "Do you want to restor the firewall first?"   -t 10 an
[ $an = "y" -o $an = "yes" ] && echo "Reatoring..." && iptables-restore < /etc/rc.d/firewall.rule

# set portforward rules
read -p "${IP}:${PORT} Is it right ? [y/n]"  -t 10 ans
ans=${ans:-"n"}
case "$ans" in
        y|Y|yes|YES)
        iptables -t nat -I PREROUTING -d 219.140.A.B -p tcp \
                 --dport $PORT -j DNAT --to $IP
        iptables -t nat -I POSTROUTING -d $IP -p tcp \
                 --dport $PORT -j SNAT --to 192.168.0.1
        echo "Have done , please check your iptables"
        ;;
        n|N|no|NO)
        echo "You canceled . Exit now"
        exit
        ;;
        *)
        echo "Only can enter y or n!"
        exit
esac

exit 0

相关阅读 更多 +
排行榜 更多 +
扑击萌兽大逃亡手游下载

扑击萌兽大逃亡手游下载

休闲益智 下载
gate交易平台app免费版

gate交易平台app免费版

金融理财 下载
Uniswap中文版app安卓版

Uniswap中文版app安卓版

金融理财 下载