Warning: imagecreatefromstring() [function.imagecreatefromstring]: Empty string or invalid image in /var/www/vhosts/tachytelic.net/httpdocs/wp-includes/media.php on line 258

Archive for Draytek

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 
Comments (0)