0

I have one VPN connection on my work PC I need constantly connected. However, it occasionally disconnects, and I discover this in a time consuming way, like thinking I have a bug in my work or something.

I would like some software tool I could use that would monitor it, maybe a PowerShell script that runs on a timer, and if it is disconnected, connect it again. Has anyone done anything like that, or is there something made for tasks like that?

2
  • 1
    "ping x.x.x.x -t " will show high latency if the link is bad or timed out if the link drops. Just enter the IP of the next hop in the network. If you want a prompt then a VB/Batch script could trigger a dialog whenever it misses a ping (or 3 say)
    – Linef4ult
    Jan 26, 2016 at 11:10
  • Thanks. Funny enough, just last night I showed a young man I mentor how to use .NET's Ping class to check the availability of a printer. I also showed him the Windows ping.exe command, for scripting the job if needed. I'll just have to find out how to reconnect now.
    – ProfK
    Jan 26, 2016 at 17:01

1 Answer 1

1

he following code will ping a certain address for you, the IP address that is stored in the $IpAddress variable. If this adress is not reachable by ping. The network adapter will be reset. Change the ip address variable to your own valid value.

rename 'Name of the connection' to the used network adapter interface name. Example: 'Ethernet'

$IpAdress = "192.168.0.1"
$ConnectionName = "ethernet"
$Testconnection = test-connection $IpAdress -count 1 -quiet

if(!$Testconnection)
{
 $nic = gwmi win32_networkadapter -filter "NetConnectionID='$ConnectionName'"
  $nic.disable()
  write-host "Disabling Network interface '$ConnectionName''"
  sleep 5
  $nic.enable()
  write-host "Enabling Network interface '$ConnectionName''"
}

Try configuring a scheduled task for the script to run every X of time to check the adapter connectivity. Or just run the script with powershell when you notice the connection is lost.

I dont know if disabling/enabling your network adapter will reconnect the VPN connection, so you might need to tweak the code a bit, though I think this will get you started in the right direction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .