Add scheduled reset support for routers (i.e., Western Digital My Net N900)

[Update] The script will work with any router that has telnet access, i.e., Dynalink Routers.

My Western Digital My Net N900 router works fine for a while, but then performance degrades requiring a reboot. I guess this is quite usual with relatively low-cost routers.

The problem is that the router doesn’t have a feature to schedule an automatic reboot and I find it quite annoying to restart manually.

Luckily there is a way to overcome this limitation of the router. You will need to have access to a Linux machine in your network that we’ll use to reboot the router remotely. I have a Raspberry Pi as HTPC which is connected to my network, and it’s on all the time, so I will be using that for this purpose.

Gain access to the router

The router can be accessed remotely is you enable “telnet” or “ssh” on it. This can be done via the web interface. My router has the IP address 192.168.1.16 and I will be using this IP in my examples, but your router might be accessible via 192.168.1.1.

To enable the telnet service you need to access this URL on your router:

http://192.168.1.16/telnet.php

wd_telnet

Once this is enabled you should be able to get access to the router:

xbian@xbian ~ $ telnet 192.168.1.16 23

Entering character mode
Escape character is '^]'.

login: Alphanetworks
Password: wrgnd15_wd_pro

BusyBox v1.18.1 (2013-04-12 18:22:04 PHT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/bin/sh: can't access tty; job control turned off
#

If you run the command “reboot” the router would reboot.

Reboot the router remotely

So far we gained access to the router, and we saw we could reboot it, but we want to do this remotely. For this, we’ll create a script on the Raspberry Pi that will log in to the router and execute the reboot command.

On the Linux box create a file named “reboot_n900” that will have this content:

reboot_n900

#!/usr/bin/expect
set timeout 10
set ip 192.168.1.16
set port 23
set username Alphanetworks
set password wrgnd15_wd_pro
spawn telnet $ip $port
expect "login:" {
 send "$username\r"
 expect "Password:"
 send "$password\r"
}
expect "#"
send "reboot\r"

Make sure the file is executable:

chmod +x reboot_n900

We will be using a script called “expect” and you will need to install this dependency:

 sudo apt-get install expect

The script needs to be run as is (do not run with sh since it’s not a shell script!):

xbian@xbian ~ $ ./reboot_n900

Now all that’s left is to schedule the script to run every night at 4am. We can add this to the cron job.

# crontab -e
0 4 * * * /home/xbian/reboot_n900

Let me know if this worked for you or if you need more details.

(in case you want to switch to a root account run: login orion orion)
(more info about wd n900: https://wiki.openwrt.org/toh/wd/n900)

Csaba is passionate about Cyber Security, Pentesting and just making things work.

2 comments: On Add scheduled reset support for routers (i.e., Western Digital My Net N900)

  • Thanks for the article. I know this was written a while back, and you may not have the WD My Net N900 anymore. But I just purchased one refurbished (same latest firmware build as shown in the picture), and can’t get telnet to remain on. If I start telnet, and use it right away, then all is fine. But if I exit a telnet session, after about 5 minutes I can no longer access it – I have to go back to “telnet.php”. It will show that telnet is on, but I have to turn it off, save, turn it on again, and save. Do you have any idea why telnet stops working? As it is right now, scheduled reboots are impossible because telnet won’t stay on.

    Also, the root telnet login (login: orion orion) doesn’t work – any thoughts?

    • Once you have telnet access, I would modify the startup script to start telnet on boot. Something along init.rd. Unfortunately I don’t have the model to test it.

Leave a reply:

Your email address will not be published.

 

Site Footer

Sliding Sidebar