How to automate VPN connections in Windows
A buddy and I at work were tinkering with a .bat file for windows to automate the connection to our Intranet via VPN. With “rasdial” its easy, but we needed an additional step. To talk to some of our systems within the network we needed to add a static route upon connection. You’ll see “%GetIp%” below–that’s the IP we get from connecting to the VPN. We use that IP in our command to add the static route. Our intranet IP addresses always start with “172.16″ and is needed in the search pattern below.
Step 1: Create your VPN connection in Windows (XP, 2000 or later) using the standard wizard thingy Windows provides.
Step 2: Create the .bat file and whatever you name the connection is the “myVPNConnection” below. Then pass in your username and password. Here’s the .bat file:
rasdial “myVPNConnection” myUserName myPassWord
setlocal
for /f “delims=: tokens=1-2″ %%c in (’ipconfig /all ^| find “IP Address” ^| find “172.16.”‘) do set GetIP=%%d
endlocal & set GetIP=%GetIP:~1%
route add 10.0.0.0 mask 255.128.0.0 %GetIp%
After you’re done creating the .bat file, simply create a shortcut to it and put it on your desktop. This way you can doubleclick it, connect and start surfing your Intranet. Superdandy handy eh?
Back to the nerdcave…






December 3rd, 2005 at 9:32 am
That IS nerdy. Does it make me a nerd that I understand it, like it, and may use it?
Ha ha. Nerds RULE
December 3rd, 2005 at 9:46 am
I’m not sure. I guess that’s your choice.
December 4th, 2005 at 9:23 am
I have no Idea what you guys are talking about or how that would even help. hrm….
December 4th, 2005 at 10:11 am
I’m with Joey…. I also have no idea. But great for those of you who do.
December 4th, 2005 at 9:30 pm
category: tech tips. ’nuff said. :p