#!/bin/sh VPN_SERVER_IP= REAL_SERVER_IP= VPN_NAME= VPN_USER= VPN_PASSWD= usage() { echo "" echo "usage:" #echo " `basename $0` -v vpn_server_ip -s real_server_ip -n vpn_name -u user -p password" echo " `basename $0` -v vpn_server_ip -s real_server_ip -n vpn_name" echo "" echo "vpn_server_ip: pptp server local ip(in server's file '/etc/pptpd.conf'), eg: 7.0.0.1" echo "real_server_ip: server ip which pptp server installed on, eg: 120.92.5.82" echo "vpn_name: pptp client vpn name, eg: ksvpn82" #echo "user: vpn user name" #echo "password: vpn password" echo "" exit 1 } while getopts :v:s:n:u:p: opt do case $opt in v) VPN_SERVER_IP=$OPTARG ;; s) REAL_SERVER_IP=$OPTARG ;; n) VPN_NAME=$OPTARG ;; u) VPN_USER=$OPTARG ;; p) VPN_PASSWD=$OPTARG ;; \?) usage ;; esac done #if [ -z $VPN_SERVER_IP ] || [ -z $REAL_SERVER_IP ] || [ -z $VPN_NAME ] || [ -z $VPN_USER ] || [ -z $VPN_PASSWD ]; then if [ -z $VPN_SERVER_IP ] || [ -z $REAL_SERVER_IP ] || [ -z $VPN_NAME ]; then echo "invalid arguments" usage fi while : do echo "checking..." date --rfc-3339=seconds until ping -c 1 $VPN_SERVER_IP > /dev/null; do echo "can not connect to vpn server ip: $VPN_SERVER_IP" sudo poff $VPN_NAME #pptpsetup --delete $VPN_NAME until ping -c 1 $REAL_SERVER_IP > /dev/null; do echo "can not connect to real server ip: $REAL_SERVER_IP" done #pptpsetup --create $VPN_NAME --server $REAL_SERVER_IP --username $VPN_USER --password $VPN_PASSWD --encrypt --start sudo pon $VPN_NAME sleep 5 done sleep 5 done