With two parents working from home and three kids playing Xbox, Switch, streaming YouTube, etc, my aging router has not been able to keep up. After a day or two of stability, we begin to see frequent dropped connections and most importantly (sarcasm intended) nobody is able to load this site. The only thing that seems to return us to that sweet stable wifi is to reboot the router.
After being tech support/router-restarter to the family for a few times, I began to search for ways to script and/or schedule this router restart routine. According to the Netgear support forums, there is no way to schedule a restart of their routers, which just isn't a satisfactory answer for this house. Buried in some comments on said Netgear forum was a linux one-liner that worked on some other model router, so I figured I'd give it a shot.
See the found Linux script below, mind the [INSERT *] blocks:
id=$(wget -q -O- --http-user [INSERT USERNAME] --http-password [INSERT PASSWORD] http://[INSERT IP]/ADVANCED_home2.htm | perl -lne '/id=([a-f0-9]+)/ && print $1'); wget -O- --http-user [INSERT USERNAME] --http-password [INSERT PASSWORD] http://[INSERT IP]/newgui_adv_home.cgi?id=$id --post-data "id=$id&buttonType=2";
Basically, the script will login, get the session id then pipe it into the subsequent reboot request. Lo and behold, it works like a charm on the R6700!
*** Note: Running this script on a Windows machine requires Windows Subsystem for Linux ***
The interoperability from Windows to Linux is so nice. Sometime in the near future, I probably should do a post on setting up WSL. But for now, just know it is a prerequisite for this router restart script.
Armed with this new tool, we can now script something with PowerShell and Task Scheduler to keep the wifi network happy.
Below, you can see PowerShell script I created that tests load time to the site, then decides whether to fire off the bash command (this command is the linux subsystem in action):
$url = "http://www.recursv.com"
$restart=0
try
{
$loadTime = (Measure-Command -Expression { $site = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 35 }).TotalSeconds
if ($loadTime -gt 30)
{
$restart=1
}
}
catch
{
$restart=1
}
Write-Output "Restart: $restart"
if ($restart -eq 1)
{
bash "/mnt/c/users/aaron/scripts/rebootRouter.sh"
}
Now, just execute that script at your chosen interval from Task Scheduler and we no longer need to manually reboot our cranky router.