Automatically reboot TP-Link router WDR4300 / N750 with bash script

I wanted to reboot some TP-Link WDR4300 routers automatically, because the TP-Link firmware is rather buggy and often causes WLAN problems after a few days of use.
Sadly, rebooting those routers with current firmwares is not quite as easy as it used to be (simple and short one-line curl call). You first have to generate a cookie with the name ‘Authorization’ and value

(pseudocode). And then you have to extract some kind of one-time key from the post-login page to get the actual HTTP address of the reboot page ( http://$IP/$KEY/userRpm/SysRebootRpm.htm?Reboot=Reboot ). Did I mention you also have to set your HTTP referer to the reboot page?

Here is a bash script that automates all that and takes three arguments (IP, username, password). Note that you have to actively click “Logout” after doing something in the web interface, otherwise this script does not seem to work:

Update 11 February, 2015:

Added delay and rudimentary check whether reboot attempt was successful.

Update 15 February, 2015:

Added option to try multiple times if the reboot attempt fails (default: 6 times).

Categories: Uncategorized

15 comments

  • ray

    Thanks a lot for sharing this! Saved me a lot of time to figure this out. Now I can use this to auto reboot when my IP cams get disconnected (indeed I also suffer from wlan problems after a few days)

  • Leigh Wiltshire

    I’m trying to build an automated tool to allow non-technical users to check link status on a TP-Link load balancing router. I know I can use curl to do this, but I’m having the same problems with authentication. My problem is that the solution will need to run on a windows PC. Any ideas on how to modify this script to work from a windows command prompt?

    • nspo

      Although it is possible to install bash, curl etc. on Windows, the better way with less overhead would be just to (re)write everything in the language that you are using for your application. Pretty much any programming or scripting language should have tools for making HTTP requests and string manipulation.

  • Giacomo

    I’ve tried this on the TD-W8968 but it isn’t working. Is there something I can do to adapt this script to this router?

    Thanks!!!

  • Gary

    Works great on my TP-Link Archer C7. The ability to reboot a router on a schedule should be a default setting in the router. Need this to be able to update my ddns with noip.com, which only seems to happen with a reboot.

  • Pieter

    This bash file doesn’t seem to work with updated firmware. Tried to use it from an RPI system.
    Firmware Version:
    3.14.3 Build 150518 Rel.70901n
    Hardware Version:
    WDR4300 v1 00000000

  • JULIO PAVEI FURLANETTO

    im running on cygwin and I het errors on lines 2, 10 and 26 saying “$’\r’: command not found”
    can you guys help me?

Leave a Reply

Your email address will not be published. Required fields are marked *