Reboot TP-Link Router TL-WA7510N using Curl
I have a TP-Link outdoor AP point router:
Hardware Version: WA7510N v2
It sometimes freezes and I need to manually reboot it. My downloads suffer and I am a bit OCDic about continuous downloads and no speed wasted.
So, I had been trying to find a way to have an automated process for that.
The router has this URL for rebooting it:
You need your username/password with curl:
(Make sure to replace the correct IP, port, username and password for your router)
CURL Command Line:
curl -D -s --header "Referer: http://192.168.1.254:8888/userRpm/SysRebootRpm.htm" -u "admin:password" "http://192.168.1.254:8888/userRpm/SysRebootRpm.htm?Reboot=Reboot"
Note: Adding referer header is very important. Without it, you will get an error:
“You have no authority to access this router”
Another way you can do this is if you can find your Authorization key.
(In case you need to keep your script out in the open. And don’t want to put your username and password for everyone to see.)
Once you login to your router in your web browser, just look at any HTTP request/response. You can use Developer tools (F12) -> Network (Chrome). Or maybe an HTTP capture tool like Fiddler, Charles etc. In any of the request/responses you capture you’ll be able to see a header like: Authorization:Basic ABCdef123456
You can use it like this:
curl -D -s --header "Authorization:Basic ABCdef123456" --header "Referer: http://192.168.1.254:8888/userRpm/SysRebootRpm.htm" "http://192.168.1.254:8888/userRpm/SysRebootRpm.htm?Reboot=Reboot"
No need to add username and password in this command. Unfortunately you’ll need to find your Authorization string manually.
You can also put this command in a batch script.
For this command to work you need to have the curl.exe in your PATH. You can download it from here:
Make sure to download the certificate file as well and keep it in the same folder as your curl.exe:
Then just add that folder to the PATH variable in your Environment Variables.
You can get to Env variables by:
– Right Click My Computer -> Properties
– Advanced System Settings
– Click Environment Variables button
If you already see a PATH var, then just add the curl.exe folder to its value separated by semi-colon.
Script to Check Internet and Reboot if necessary
This is a very helpful script which will check your internet connection by running a ping command for: google.com
If ping works then the script will exit. If however the ping fails or there is a certain amount of packet loss means something is wrong.
So it will reboot the router.
I have modified the vbscript I found on this site:
Thank you Noah Davids for this cool script!
I have hard coded some variables and changed some lines to suit my needs.
I have also created a Scheduled Task to run this script every 30 minutes and keep a check on my connection.
Everything gets logged so I have a good idea of how many times the router needed a reboot.
REM === ping_trigger.vbs begins here === REMREM ping_trigger.vbsREM Version 1.0 06-11-05REM Version 1.1 10-11-26 Added disclaimerREM Noah Davids - firstname.lastname@example.orgREMREM pings "TargetIPAddress" (argument 1) for a "PingCount" (argument 2) of times and if REM "FailureCount" (argument 3) pings or more are lost it will execute "CommandToExecute" (argument 4).REM The script will then either exit or continue based on the value of "StopOrContinue" (argument 6).REM If fewer than "FailureCount" pings are lost or "StopOrContinue" says to continue the script willREM sleep for "SleepTime" (argument 5) seconds and then start over pinging "TargetIPAddress".REMREM Failures are indicated with a message in the command window that the script is executing in andREM also written to a log named pt.HH_MM_SS.results.txt where HH is the hour, MM is the minute andREM SS is the second of when the script was started. There is also a working file namedREM pt.HH_MM_SS.temp that is used to hold the results of the last ping command. Both files are createdREM in the current working directory. Neither file is automagically deleted so if you run this scriptREM multiple times these files will build up. REMREM This software is provided on an "AS IS" basis, WITHOUT ANY WARRANTY OR ANY SUPPORT OF ANY KIND. REM The AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANYREM PARTICULAR PURPOSE. This disclaimer applies, despite any verbal representations of any kind providedREM by the author or anyone else.REMoption explicitdim TargetIPAddressdim PingCountdim FailureCountdim CommandToExecutedim StartTImedim WshShelldim objFSOdim objFiledim messagedim TempPathdim ResultsPathconst ForReading = 1Const ForWriting = 2const ForAppending = 8dim FileTextdim TextPosSet objFSO = CreateObject ("Scripting.FileSystemObject")TargetIPAddress = "google.com"PingCount = 3FailureCount = 1CommandToExecute = "curl -D -s --header ""Referer: http://192.168.1.254:8888/userRpm/SysRebootRpm.htm"" -u ""admin:password"" ""http://192.168.1.254:8088/userRpm/SysRebootRpm.htm?Reboot=Reboot"" > /dev/null"StartTime = timeif (Mid (StartTime, 2, 1) = ":") then message = Mid (StartTime, 1, 1) & "_" & Mid (StartTime, 3, 2) & "_" & Mid (StartTime, 6, 2)else message = Mid (StartTime, 1, 2) & "_" & Mid (StartTime, 4, 2) & "_" & Mid (StartTime, 7, 2)end ifTempPath = "D:\DEV\SCRIPTS\logs\" & "check_router_reboot" & ".temp"ResultsPath = "D:\DEV\SCRIPTS\logs\" & "check_router_reboot" & ".results.txt"Set WshShell = WScript.CreateObject ("WScript.Shell")WshShell.Run "Cmd.exe /c ping " & TargetIPAddress & " -n " & PingCount & " > " & TempPath, 0 , Trueset objFile = objFSO.OpenTextFile (TempPath, ForReading)FileText = objFile.ReadAllobjFile.Closeif objFSO.FileExists(TempPath) then objFSO.DeleteFile TempPathend ifTextPos = Instr (FileText, "Lost =")if (TextPos = 0) then WScript.Echo "Problem with " & TempPath & " file, cant find Lost count - QUITING" WScript.Quitelse FileText = Mid (FileText, TextPos + 7) TextPos= Instr (FileText, " ") FileText = Mid (FileText, 1, TextPos - 1) set objFile = objFSO.OpenTextFile (ResultsPath, ForAppending, True) objFile.WriteLine vbCRLF & "**************************************** " if cInt(FileText) >= FailureCount then message = Now & " packets lost <<" & FileText & ">> " & "Rebooting..." WshShell.Run "Cmd.exe /c" & "" & CommandToExecute & "", 0 , True else message = Now & " Running fine." end if objFile.WriteLine vbCRLF & message objFile.Closeend ifWScript.QuitREM === ping_trigger.vbs end here ===
Hope this helps anyone facing a similar issue.