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...).