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
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