VPN 创建 VBS脚本

'Program:     PPTP Route Addition Script
'Author:        Joshua R. Cook
'Website:       http://www.joshcook.net/
'Date:          1.13.2005
'***********************
'Task: Variable Creation

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

'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 = "xxx.xxx.xxx.xxx"

'The route command that should be executed, without the gateway
' - route add *network* mask *netmask*
RouteCommand = "route add 192.168.xx.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

作者: linuxfly   发布时间: 2010-11-08