Clicky

How to Connect to VPN Using Command Line on Windows XP | suksit dot com

How to Connect to VPN Using Command Line on Windows XP

เพิ่งค้นพบวิธีเชื่อมต่อ VPN บนวินโดวส์ โดยใช้ command line คำสั่งที่ใช้คือ

rasdial <connection name> <username> <password>

แต่ปรากฏว่าทุกครั้งที่ต่อ VPN เสร็จ วินโดวส์จะตั้ง default gateway เป็น IP ของเครื่องที่ได้จาก VPN ซะงั้น ทั้งๆ ที่จริงๆ gateway ที่ต้องการ คือ gateway ที่ตัว VPN server ใช้อยู่ วิธีแก้คือต้องเซ็ต route ใหม่ทุกครั้งที่ทำการเชื่อมต่อ

ด้วยความขี้เกียจ เลยพยายามเขียน batch file ให้มันแก้ route ให้เอง แต่ติดปัญหาตรง interface name ของ WAN (PPP/SLIP) ที่ได้ในการเชื่อมต่อแต่ละครั้งมันไม่แน่นอน ทำให้เขียน batch สคริปต์ลำบาก

ยังดีที่มี Cygwin เลยอาศัยลูกมั่ว เขียน shell script โดยใช้คำสั่ง DOS ผสม Unix เพื่อหาชื่อ interface แล้วค่อยเอาไปเซ็ต route ต่ออีกที ปรากฏว่าได้ผล รันได้แบบเนียนๆ หน้าตาก็เป็นประมาณนี้

#!/bin/bash
 
rasdial MyVPN user password
ifname=`route print | grep "WAN (PPP\/SLIP) Interface" | cut -f1 -d\ `
route delete 0.0.0.0
route -p add 0.0.0.0 mask 0.0.0.0 192.168.1.1 if ${ifname} metric 1

1 comment

comforu.com's picture
comforu.com (visitor) says:

Thanks

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.