Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

route add command - explain the syntax?

Status
Not open for further replies.

random260

Programmer
Mar 11, 2002
116
US
Entire script at bottom of post.

This is a vb script for adding routes through a vpn connection automatically. I posted in another section to find out how to run it, now I just have a couple of questions about the syntax here.

I think I understand most of this script - for instance, I know that the VPN server assigns me 10.42.49.### when I connect (according to ipconfig), where ### is between 100 and 110, so in the section

'The IP range that is provided to PPTP clients, without that last octet (this is used for matching purposes)
PPTPNetwork = "192.168.1."

I assume I replace 192.168.1. with 10.42.49. (or do I replace it with 172.16.100. - which is the address range of the computers at the network I am dialing IN to... or do I replace it with 192.168.50. - which is MY network address range...?)

Also....

About 1/2 down the script is the section:

'The route command that should be executed, without the gateway
' - route add *network* mask *netmask*
RouteCommand = "route add 10.0.0.0 mask 255.255.255.0"

I see that *network* has been replaced with 10.0.0.0 and *netmask* with 255.255.255.0

I'm not sure what I am supposed to be replacing 10.0.0.0 mas 255.255.255.0 with? This is the biggest question I have.

Here is the entire script. Thanks!

'Program: PPTP Route Addition Script
'Author: Joshua R. Cook
'Website: 'Date: 1.13.2005

'***********************
'Task: Variable Creation

'In Windows, the name of the VPN connection as it is appears in Network Connections
VPNConnection = "My Work VPN"

'The username for the VPN connection
VPNUsername = "username"

'The password for the VPN connection
VPNPassword = "password"

'The IP range that is provided to PPTP clients, without that last octet (this is used for matching purposes)
PPTPNetwork = "192.168.1."

'The route command that should be executed, without the gateway
' - route add *network* mask *netmask*
RouteCommand = "route add 10.0.0.0 mask 255.255.255.0"

'*********************************
'Task: Establish Dialup Connection

Set Shell = CreateObject("WScript.Shell")
Shell.Run "Rasdial " & VPNConnection & " " & VPNUsername & " " & VPNPassword, 6, True
Set Shell = Nothing

'*********************************
'Task: Obtain *Correct* IP Address

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objAdapter In colAdapters

If InStr(objAdapter.IPAddress(0), PPTPNetwork) > 0 Then VPNIPAddress = objAdapter.IPAddress(0)

Next

Set colAdapters = Nothing
Set objWMIService = Nothing

'*************************
'Task: Add Route Statement

Set Shell = CreateObject("WScript.Shell")
Shell.Run RouteCommand & " " & VPNIPAddress, 6, True
Set Shell = Nothing
 
I'd have thought you'd want a route to the computers you want to connect to with a gateway of the VPN server, i.e. something like:

RouteCommand = "route add 172.16.100.0 mask 255.255.255.0 x.x.x.x"
where x.x.x.x is the default gateway address for the VPN clients

You're omitting the default gateway but I wouldn't expect this to be accepted on Windows OS systems. Why are you doing that?
 
I should have explained - this script is to help create a split tunnel VPN - so that Internet traffic goes out through the local connection while Interesting traffic goes through the VPN. The article explainging this code (very brief) can be found at


After reading that, do you still think it should be the 172?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top