• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Tachytelic.net

  • Get in Touch
  • About Me

Automated and conditional reboots of Draytek routers via telnet

May 25, 2010 by Paulie 2 Comments

This is a script that I posted to the Draytek forum a couple of years ago, I noticed that it has been a very popular post so I have decided to post here also.

The function of the script is to perform scheduled reboots of Draytek routers.  Optionally is it possible to reboot the router only if a specified IP address does not respond to a ping request.  This is useful to test if a VPN connection is functioning, and only reboot the router if there is no response.

Early Draytek firmwares had a tendancy to lose VPN connectivity and a reboot is the only way to restore the connection.

First of you need to install the Toolsack Baseline components for this script to work:

http://www.toolsack.com/download/

The script needs to be supplied with parameters, so a typical command line would look like this:

cscript reboot.vbs 86.11.93.131 routerpassword

and a conditional command line would look like this:

cscript reboot.vbs 86.11.93.131 routerpassword 192.168.1.254

The 3rd argument will be tested for a ping response, if none is received then a reboot will be executed.

Here is the code, save it as reboot.vbs:

set args=wscript.arguments

If wscript.arguments.count=2 then
   IP=args.item(0)
   Password=args.item(1)
   call reboot(IP,Password)
elseif wscript.arguments.count=3 then
   IP=args.item(0)
   Password=args.item(1)
   TestIP=args.item(2)   
   if ping(TestIP)=False then
      call reboot(IP,Password)
   end if
else
   wscript.echo "Invalid number of arguments specified"
   wscript.echo "Please specify router IP address & password and optional test IP"
end if

sub reboot(IP, Password)
   set s = CreateObject("Toolsack.Socket")
   s.Connect IP, 23
       s.Write Password & vbCrLf
   s.write "sys reboot" & vbcrlf
   s.write "quit" & vbcrlf
end sub

Function Ping(strHost)

    dim objPing, objRetStatus

    set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = '" & strHost & "'")

    for each objRetStatus in objPing
        if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
       Ping = False
        else
            Ping = True
        end if
    next
End Function

Filed Under: Scripts & Utilities, Technical Posts

Reader Interactions

Comments

  1. B Greenshield says

    August 28, 2018 at 3:05 am

    Is there any other source to get the com object? toolsack.com seems to be gone.

  2. Paulie says

    September 4, 2018 at 12:32 am

    I had a good look around and I was not able to find it, what a shame.

Leave a Reply Cancel reply

Primary Sidebar

Link to my LinkedIn Profile
Buy me a coffee

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 245 other subscribers.

Go to mobile version