Copy the following code and save it as a batch file somewhere at your computer - e.g. CHECK_HOST.bat
Follow the instructions in the REM - comments.
Code: Select all
@ECHO OFF REM This script will test if your Internet connection or a spesific host REM is down. If it is down after 4 tries it will power cycle it with REM your Telldus. REM Script made by ag at xlntit dot no. If you have any q's or REM improvements send me a mail or go to REM http://www.telldus.se/forum/viewtopic.php?t=492 REM If a host is down it will be logged to a file called CHECK_HOST.log REM in the folder that the script is executed from. REM You probably want to run the script as a scheduled task REM e.g. every 10 or 20 minutes. REM REM You can do so by setting it to run daily at 00:00. In the REM properties of the sceduled task go to the schedule tab and click REM advanced - set it to repeat task until 23:59. REM REM To make sure that the script runs minimized as a scheduled task REM make a shortcut to the script - go to properties on the shortcut REM and set it to run minimized. After you have made the scheduled REM task edit the schedule and make sure the RUN command is pointing REM to the shortcut (should be .lnk - not .bat). REM Below is a few lines that should be set according to your setup. REM Set the path to tdtool.exe - include " " if there is a space in the path set TDTOOL="C:\Program Files\Telldus\tdtool.exe" REM Set the device number that you want to power cycle if host is down set DEVICENUM=5 REM IPs to test. If you test if the Internet is up you can probably leave REM the IPs that I have set. REM If you want to test your own internal IP (PC/server/ip-phone/whatever) REM you can set all the 4 IPs to the same IP. Then that one IP will be REM tested 4 times. set IP1=184.108.40.206 set IP2=220.127.116.11 set IP3=18.104.22.168 set IP4=22.214.171.124 REM Time to wait between testing each IP in millisec (1000=1sec / 60000=1min) REM There will be three waiting times, so if it is set to 60000 the IPs will REM be checked over a time of 3 minutes. REM I recomend to set it to around 60000 - then if you are currently manualy REM restarting your Internet/host it will have about 3 minutes to be up and REM running before this script take it down for a power cycle. set WaitTime=60000 REM No need to edit below this line unless you like hacking :-p REM -------------------------------------------------------------------------- set BinDown=0 REM Test IP 1 PING -n 1 %IP1% | FIND "Reply from %IP1%" > NUL IF NOT ERRORLEVEL 1 GOTO REMOTE_FOUND ECHO %DATE% %TIME% HOST/NET is DOWN 1 >>CHECK_HOST.log set BinDown=1 REM ping fake address just for waiting PING 10.121.212.121 -n 1 -w %WaitTime% >NUL REM Test IP 2 PING -n 1 %IP2% | FIND "Reply from %IP2%" > NUL IF NOT ERRORLEVEL 1 GOTO REMOTE_FOUND ECHO %DATE% %TIME% HOST/NET is DOWN 2 >>CHECK_HOST.log PING 10.121.212.121 -n 1 -w %WaitTime% >NUL REM Test IP 3 PING -n 1 %IP3% | FIND "Reply from %IP3%" > NUL IF NOT ERRORLEVEL 1 GOTO REMOTE_FOUND ECHO %DATE% %TIME% HOST/NET is DOWN 3 >>CHECK_HOST.log PING 10.121.212.121 -n 1 -w %WaitTime% >NUL REM Test IP 4 PING -n 1 %IP4% | FIND "Reply from %IP4%" > NUL IF NOT ERRORLEVEL 1 GOTO REMOTE_FOUND REM Host/net is down and we will power cycle it ECHO %DATE% %TIME% HOST/NET is DOWN 4 - POWER CYCLE DEVICE %DEVICENUM% >>CHECK_HOST.log %TDTOOL% --off %DEVICENUM% %TDTOOL% --off %DEVICENUM% PING 10.121.212.121 -n 1 -w 5000 >NUL %TDTOOL% --on %DEVICENUM% %TDTOOL% --on %DEVICENUM% GOTO END :REMOTE_FOUND REM HOST/NET is UP IF %BinDown%==1 echo %DATE% %TIME% HOST/NET is UP again >>CHECK_HOST.log GOTO END :END