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

2 thoughts on “Scripting telnet commands for a Draytek Vigor router

  1. A good solution; but I am more worried that you have a need to do this; as we have used Draytek routers for about 8-10 years for ourselves and our clients and found glitches and reboots to be a rare thing indeed. I would suggest that you check your firmware (of the router and possibly the ADSL firmware code, if you are not on fibre) in case a bug fix/update is contained in the update; but I suspect you have done that; so my next step would be to log a technical support call with Draytek’s UK arm – SEG.

  2. LOL… Brilliant post, I needed this about 2 weeks ago! The solution I found is very similar, but uses a set of free COM objects to pass the commands to the router.
    http://www.tachytelic.net/2010/05/automated-and-conditional-reboots-of-draytek-routers-via-telnet/
    I have tested this with an ageing Vigor 2600 and a more up-to-date Vigor 2850, the only tweak needed is to add a line to pass the “admin” login name before the password for the newer routers.
    I can’t vouch for the quality of the ToolSack download, but have virus checked it and it came back clean.
    Thanks for the post.

Let us know what you think....

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s