
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:
http://192.168.1.254:8888/userRpm/SysRebootRpm.htm?Reboot=Reboot
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.
Get CURL:
For this command to work you need to have the curl.exe in your PATH. You can download it from here:
http://curl.haxx.se/download.html
Make sure to download the certificate file as well and keep it in the same folder as your curl.exe:
http://curl.haxx.se/ca/cacert.pem
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:
http://www.noahdavids.org/self_published/ping_trigger.html#the_macro
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.
Script:
REM === ping_trigger.vbs begins here ===
REM
REM ping_trigger.vbs
REM Version 1.0 06-11-05
REM Version 1.1 10-11-26 Added disclaimer
REM Noah Davids - [email protected]
REM
REM 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 will
REM sleep for "SleepTime" (argument 5) seconds and then start over pinging "TargetIPAddress".
REM
REM Failures are indicated with a message in the command window that the script is executing in and
REM also written to a log named pt.HH_MM_SS.results.txt where HH is the hour, MM is the minute and
REM SS is the second of when the script was started. There is also a working file named
REM pt.HH_MM_SS.temp that is used to hold the results of the last ping command. Both files are created
REM in the current working directory. Neither file is automagically deleted so if you run this script
REM multiple times these files will build up.
REM
REM 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 ANY
REM PARTICULAR PURPOSE. This disclaimer applies, despite any verbal representations of any kind provided
REM by the author or anyone else.
REM
option explicit
dim TargetIPAddress
dim PingCount
dim FailureCount
dim CommandToExecute
dim StartTIme
dim WshShell
dim objFSO
dim objFile
dim message
dim TempPath
dim ResultsPath
const ForReading = 1
Const ForWriting = 2
const ForAppending = 8
dim FileText
dim TextPos
Set objFSO = CreateObject ("Scripting.FileSystemObject")
TargetIPAddress = "google.com"
PingCount = 3
FailureCount = 1
CommandToExecute = "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 = time
if (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 if
TempPath = "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 , True
set objFile = objFSO.OpenTextFile (TempPath, ForReading)
FileText = objFile.ReadAll
objFile.Close
if objFSO.FileExists(TempPath) then
objFSO.DeleteFile TempPath
end if
TextPos = Instr (FileText, "Lost =")
if (TextPos = 0) then
WScript.Echo "Problem with " & TempPath & " file, cant find Lost count - QUITING"
WScript.Quit
else
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.Close
end if
WScript.Quit
REM === ping_trigger.vbs end here ===
Hope this helps anyone facing a similar issue.
I am trying to run this on raspbian and all i am getting is this:
window.parent.document.cookie=”Authorization=;path=/”;
window.parent.document.cookie=”TPLoginTimes=0;path=/”;
window.parent.location.href=”/”;
can somebody help. I know it is logging in since its not a mail failure
Work perfeclty!!!