IP range in command line

dreamerman

Distinguished
Jan 20, 2008
58
5
18,535
I am looking to use powershell and task scheduler in windows 7 ultimate 32 bit to redial vpn should the vpn connection drops. I found a scrip ( http://blog.degree.no/2011/10/permanent-vpn-connection-in-windows/ ) but it only have one IP address. What I need is a range of IP address like 10.0.0.0/16 because of the way my vpn assigns IP addresses. Can anyone help me out please?

Create c:\pn.ps1 and add the following:

$ip = "10.20.30.40"
$result = gwmi -query "SELECT * FROM Win32_PingStatus WHERE Address = '$ip'"
if ($result.StatusCode -eq 0) {
Write-Host "$ip is up."
}
else{
Write-Host "$ip is down."
Write-Host "Disconnecting..."
rasdial.exe DegreeVPN /DISCONNECT
Write-Host "Connecting..."
rasdial.exe DegreeVPN vpnUsername vpnPassword12345
}

 
Solution
Only to make sure: 10.20.30.40 is the address of the vpn server here. If it is a server farm in your case and the actual ip keeps changing, there has to be a DNS name you can ping instead.

dreamerman

Distinguished
Jan 20, 2008
58
5
18,535


Your comments gave me an idea. Can I ping say google.com from a PPTP adapter? If the vpn is down, the PPTP adapter will drop out so pinging will be impossible.
 
That is actually a better test since you are testing end to end which would include issues where the vpn software is messed up even though the internet itself is up and running.

This is why commercial installations run a routing protocol over the vpn. It combines all the detection and path selection without the need for user written scripts. Still it tends to not be worth the effort to setup when you don't really have a redundant path to choose.