2007-09-07

Smart PPTP connect/disconnect scripts for XP

When you are using PPTP connection in XP, you get the situation when the connection is established, that XP sets the default routing to your established PPTP connection, that is why some of your local network connectivities can be broken.

The following script establishes the selected PPTP connection and modifies the routing table to preserve your local connectivities:

rasdial PPTP-CONN username password
for /f "skip=3 tokens=3" %%a in ('netsh diag show ip Miniport*') do set VPNIP=%%a
route add 172.19.0.0 mask 255.255.255.0 %VPNIP%
route add 0.0.0.0 mask 0.0.0.0 192.168.1.1

This script assumes that you local network is 192.168.1.0/255.255.255.0, your remote network over PPTP VPN is 172.19.0.0/255.255.255.0, and your PPTP connection name is `PPTP-CONN'. You should customize it (including user name and password) for your setting.

Disconnect script:

rasdial OTS-PPTP /disconnect

5 comments:

Anonymous said...

This is great! I've had the same problem, only I had statically defined all possible remote ips. btw: I added this to grab the original gateway before the rasdial command so that the second route add command could be dynamic as well.

for /f "skip=3 tokens=3" %%a in ('netsh diag show gateway') do set GATEWAY=%%a

Retro said...

Hello! I have the same problem, but the script does not seem to run correctly. It does not add instead VPNIP the gateway, leaving the field empty, and the route add command files.
Here it how looks -
C:\>for /F "skip=3 tokens=3" %a in ('netsh diag show ip Miniport*') do set VPNIP
=%a

C:\>route add 192.168.110.0 mask 255.255.255.0

as you can see, at the end there is no gateway ip, so command files. ANybody can help about this please?

Anonymous said...

to Retro
for Vista-7
netsh interface ipv4 add route 192.168.2.0/24 VPN-name

Anonymous said...

Hello, i think that i saw you visited my site thus i came to ?
return the favor?.I'm attempting to find things to enhance my website!I suppose its ok to use a few of your ideas!!

my webpage; rent property

Anonymous said...

All you hear as you meander through the holly-strewn stores is Christmas music about joy
and cheer, but if you want to place in storage.
In January, XBIZ, a fleshlight website that adheres to the
best practices of traditional journalism, including fact-checking,
accuracy, and fairness.