0

I can establish VPN connection using RASDIAL command. But how do I add a route to 192.168.254.0/24 automatically after VPN is connected? Each time after VPN connection is established, Windows could assign different interface ID to the VPN connection (the IF parameter to the ROUTE command).

I can do that manually using the following method. ROUTE PRINT command shows a list of interfaces, I can write down an interface ID for the VPN (42 for example) and then issue a command

route ADD 192.168.254.0 MASK 255.255.255.0 192.168.0.200 IF 42

But how can I do this automatically in the .bat file?

I'm using PPTP VPN (it cannot automatically push routing to client).

Since interface ID is different each time VPN connects, I cannot use route -p (add a persistent route on clients). BTW, this is not a good solution, since VPN connection is sometimes used on office staff's notebooks. Sometimes their notebooks are part of the network, that is already a part of VPN and sometimes they establish VPN connection themselves.

This is a solution for PowerShell and it's ok for me. But I'm curious, can the same be done via simple .bat file?

2
  • You can also try to use the option 121 of dhcp server to automatically push routes to clients?
    – user132796
    Aug 20, 2012 at 13:16
  • Yea, but I just think, are .bat files powerful enough to do the task... Aug 20, 2012 at 14:04

2 Answers 2

2

I had tried to find any good working solution too and failed and after that I decided to write it by myself. You can use it if you still need it. http://www.latestbit.com/winvpnhelper

2
  • Miraculous!!! ;) Jan 3, 2013 at 16:31
  • I hope it's working very well for you. If you have any issues please inform me. Enjoy!
    – abdolence
    Jan 4, 2013 at 17:07
0
@echo of
FOR /F "tokens=2 delims=:" %%a in ('IPCONFIG ^|FIND "IP" ^|FIND "192.168.99"') do set _IP=%%a 
set GW=%_IP:~1% 
echo %GW%
route add 192.168.99.0 mask 255.255.255.0 %GW% 
route add 192.168.236.0 mask 255.255.255.0 %GW% 
1
  • Please add some comments explaining what your script does and why it would help OP instead of just posting a bunch of code.
    – Frederik
    Mar 27, 2016 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .