0

I am running a Windows 10 computer which I need to be able to remotely access when away from home. I use a VPN service on this computer and when left on for extended periods of time, the connection will often drop, putting the system into a state where the VPN client thinks it is still connected, but isn't. The client never tries to reconnect, since it believes it is still connected, and non-VPN traffic is also blocked (like a sort of unintentional kill switch). This results in a situation where an unintentional kill-switch prevents me from accessing my computer remotely.

Rebooting the computer automatically when the internet appears to be unreachable for a period longer than 5 minutes is my end goal, but I'm not sure how to go about it. I would appreciate if someone could help me design a script that would reboot the computer in this kind of situation. I'm not all that familiar with cmd or powershell scripting, but here's a little pseudocode demonstrating the process I'm looking to script, in a way that it can be run with the built-in tools/software included with my OS, e.g. powershell or batch.

// Note- PSEUDO-CODE, NOT A USABLE SCRIPT AS-IS
ping 8.8.8.8 // check for internet connection. 0% packet returns would indicate the computer had probably entered this network lock-up
if pingsReturned == 0
{
    wait 5 minutes // in case of temporary disconnect, give the network time to reestablish itself
    ping superuser.com // alternate site used to confirm google isn't the only site I can't connect to, i.e. google is down, not my network connectivity
    if pingsReturned == 0
        shutdown /f /r /t 60 /c "Rebooting due to connection issues." 
    else
    {
        exit
    }
}
else
{
    exit
}

I'd plan on running this as a task that runs at 5 minute intervals in the task scheduler if possible. I've poked around the internet (and this site specifically) looking for solutions, but found none for Windows, though I did find a very similar implementation for Linux setups (which coincidentally also used Google's DNS as a test, or perhaps that's just a go to site for ping tests in general...).

  • Why not just enable keep alive packets in your VPN client? – Daniel B Sep 8 '16 at 7:24
  • @Daniel B That might be easier if the client had the option, but it doesn't. I am using the official TigerVPN client. TigerVPN IS compatible with the OpenVPN GUI, but even with the DNS leak plugin, I still get occasional leaks when using it. – Matthew Sep 8 '16 at 22:58
0

I guess something like this should do the trick

:: ping google
ping www.google.com -n 1 | find "TTL=" >nul
if errorlevel 1 (
    :: wait 60 seconds
    ping 127.0.0.1 -n 60 > nul

    :: ping another
    ping www.facebook.com -n 1 | find "TTL=" >nul
    if errorlevel 1 (
        echo Rebooting...
        shutdown /r
    ) else (
        echo We're back up again
    )
) else (
    echo We're up
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.