How to make a script that adds a network route?


SO Windows 7

I need to connect to remot host via cisco vpn. Sometimes the host destination network is the same of local network. Example (Partial output of ipconfig command):

Ethernet adapter Cisco Vpn Adapter:
   IPv4 Address. . . . . . . . . . . :
   Subnet Mask . . . . . . . . . . . :

Wireless LAN adapter Wireless Network Connection:
   IPv4 Address. . . . . . . . . . . :
   Subnet Mask . . . . . . . . . . . :

I need to connect to host on the remote network via Vpn Then I need to add new route (in this configuration all traffic to are route to local network) The output of route print begining by:

Interface List
 17...00 05 9a 3c 78 00 ......Cisco Systems VPN Adapter
 12...00 16 44 ea 74 58 ......Dell Wireless 1395 WLAN Mini-Card

And the command is: route add mask metric 1 if 17

Problem: The Ip on Cisco adapter is not static, i can't route add with modifier -p (permanent) When disconected and reconnect I need look for the NewIp and add the correct route: route add mask ┬źNewIP┬╗ metric 1 if 17 For me its easy (but boring) write all this commmands every time:

ipconfig  etc
route print etc
route add etc

I need a bat or powershell script to add the correct route. The scrip look for the ip on the Cisco adapter and run the command route add with Ip gateway founded.


PD Sory my poor english


I tried renegm's answer, and the Index property gives the wrong value for me. This worked for me though (Juniper VPN here, but the same problem) - note InterfaceIndex instead of Index:

$adapter=Get-WmiObject Win32_NetworkAdapterConfiguration|
    Where-Object { $_.Description -match "Juniper Network Connect Virtual Adapter"}

route add mask $Gateway metric 1 $if

I solved it. (I'm a complete newbie in PowerShell, but problem is very simple)

$adapter=Get-WmiObject Win32_NetworkAdapterConfiguration|
    Where-Object { $_.Description -match "Cisco Systems VPN Adapter"}
route add mask $Gateway metric 1 if $if

This is a pretty old discussion, but you could use the following PowerShell command to create a route AFTER you're connected to VPN:

Add-VpnConnectionRoute -ConnectionName "You VPN Name Here" -DestinationPrefix

It worked on Windows 10.

Need Your Help

Missing responseJSON in jquery ajax Response

javascript jquery json ajax node.js

I'm working on a small web framework to run a HCI study in and came across the following problem: