Chinaunix首页 | 论坛 | 博客
  • 博客访问: 543296
  • 博文数量: 119
  • 博客积分: 3167
  • 博客等级: 中校
  • 技术积分: 1215
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-20 21:21
文章分类

全部博文(119)

文章存档

2015年(21)

2012年(4)

2011年(1)

2007年(11)

2006年(50)

2005年(32)

分类: LINUX

2006-01-15 02:05:30

#!/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

阅读(1289) | 评论(0) | 转发(0) |
0

上一篇:script : check_conn.sh

下一篇:FC1里面使用VNC

给主人留下些什么吧!~~