Scripting telnet commands for a Draytek Vigor router

Just like a lot of our customers we use multiple ADSL broadband lines for our Internet access in the office and occasionally we have seen a line issue that effects our Draytek Vigor router and the only fix we have found is a quick controlled reboot.

The Problem

During office hours it is not ideal to reboot the router but easy to perform via the web interface, but when the problem happens out of hours it can be very difficult to gain remote access to trigger the reboot, as the office VPN connection is also effected.

We had tried running a scheduled daily reboot but this is not an ideal fix as the problem can be very sporadic so it seems overkill to reboot the router every day, and besides when it fails you still have to wait until the next scheduled reboot.

What was needed was an automatic process to detect and reboot the Draytek router if the problem happens.

Luckily the first part of this process was already in place – we can detect the problem using our Network Monitoring System.

This detects when a specific external host becomes unavailable and emails us about the issue. It can also easily be told to run an external Windows command – but what command can I run to reboot the router?

This is where we need some extra tools.

Using Telnet to control the router

First lets look at what actually needs to happen.

Draytek Routers are very powerful and flexible devices and other than the web management interface they also run a telnet server on the LAN side that can allow you to issue specific commands via a command line. By running the Windows built in telnet command I can telnet to the routers internal IP address using…

telnet 172.17.9.254

This presents me with a login Prompt…

Account:

Here I enter ‘admin’

the router then asks for the password..

Password:

I enter the web interface password and finally get presented with the services page.

Here if i enter the command…

sys reboot

..and click enter the router immediately reboots in a controlled way.

This is great as I can now reboot the router quickly using just the command line but what I need is a way to fully automate this task.

Unfortunately this is where the Microsoft telnet command lets us down. There is no easy way to script this process, as the command expects the user to enter the details line by line.

What we need is a more powerful telnet tool that can be scripted..

Introducing Telnetd

Luckily a short time googling reveals just what we need…

https://coherent-ascent-678.appspot.com/

Unfortunately I don’t have much information on this developer and so cannot verify the authenticity of the download, so please use usual caution here, but I have scanned it with multiple AV tools and have tested it and all looks good to me.

I’m sure they may be other similar tools out there that do the same but if you do want to try the one above it is a simple case of extracting the download zip file to a new folder and editing the CVSTART.txt text file to define the server and log in details as well as adding the command we need.

The download should contain the following files…

For reference I edited my CVSTART.txt file looks like this..

TELNETID=server1
IP=172.17.9.254
PORT=23
RETRY=1
TIMEOUT=10
SLEEP=0
1->Account:=admin
2->Password:=password123
3->>=sys reboot
4->>=exit

Be careful to keep the each numbered command in the correct format for example command 3 in this example..

3->>=sys reboot

3->‘ is the third command

>‘ is the prompt the telnet tool is waiting for

sys reboot‘ is the command to be sent (Note an <enter> will be added afterwards)

Now all you need to do to run the scripted telnet command is start the ‘Restart.bat’ batch file and the Draytek router will reboot within a few seconds.

I hope you have found this useful and may be able to use the same method to schedule all kinds of activity on devices running telnet services. If you do have any other interesting uses please feel free to let me know.

 

Subscribe to blog highlights mail



Share via
Copy link
Powered by Social Snap