aphesia Posted April 15, 2015 Posted April 15, 2015 Good morning everyone, I have a little script which checks whether a device is online in my network or not by pinging it's ip. So far my script has been working but suddenly it won't detect the ping answer "Destination host unreachable" as ping = 0 (error) anymore: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.5.6 (beta) Author: Patrick Schneider Script Function: Checks if I´m back at home with my laptop. If so, it will enable the scheduler in uTorrent to slow down the upload rate. It will update the ipfilter.dat & restart uTorrent. Also included a log file to check when an update is done and which device enables the scheduler. lan laptop 192.168.178.30 wlan maci 192.168.178.67 lan maci 192.168.178.22 lan laptop: 192.168.1.17 lan maci: 192.168.1.22 wlan maci: 192.168.178.67 Laptop = offline.......$status = 0 Scheduler = disabled.......&scheduler = 0 #ce ---------------------------------------------------------------------------- #include <Date.au3> If ProcessExists("uTorrent.exe") Then Sleep(10000) Else ProcessWait("uTorrent.exe") Sleep(10000) EndIf If FileExists(@ScriptDir & "\status.ini") = 0 Then MsgBox(0, "First run", "Please enable the scheduler in uTorrent. Afterwards press OK") IniWrite(@ScriptDir & "\status.ini", "Server status", "Devices Online", "No") IniWrite(@ScriptDir & "\status.ini", "Devices", "My_Laptop", "Offline") IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_LAN", "Offline") IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_WLAN", "Offline") IniWrite(@ScriptDir & "\status.ini", "Server status", "Scheduler", "Enabled") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP1", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP2", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP3", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP4", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP5", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP6", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP7", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP8", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP9", "0") IniWrite(@ScriptDir & "\status.ini", "IPs", "IP10", "0") EndIf While 1 $IP1 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP1", "NotFound") $IP2 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP2", "NotFound") $IP3 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP3", "NotFound") $IP4 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP4", "NotFound") $IP5 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP5", "NotFound") $IP6 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP6", "NotFound") $IP7 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP7", "NotFound") $IP8 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP8", "NotFound") $IP9 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP9", "NotFound") $IP10 = IniRead(@ScriptDir & "\status.ini", "IPs", "IP10", "NotFound") $maciwlan = Ping($IP4, 1000) $macilan = Ping($IP3, 1000) $mylaptop = Ping($IP1, 1000) $mylaptop2 = Ping($IP2, 1000) If $maciwlan = 0 And $macilan = 0 And $mylaptop = 0 And $mylaptop2 = 0 And $IP5 = 0 And $IP6 = 0 And $IP7 = 0 And $IP8 = 0 And $IP9 = 0 And $IP10 = 0 Then Sleep(60000) If $maciwlan = 0 And $macilan = 0 And $mylaptop = 0 And $mylaptop2 = 0 And $IP5 = 0 And $IP6 = 0 And $IP7 = 0 And $IP8 = 0 And $IP9 = 0 And $IP10 = 0 Then IniWrite(@ScriptDir & "\status.ini", "Server status", "Devices Online", "No") IniWrite(@ScriptDir & "\status.ini", "Devices", "My_Laptop", "Offline") IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_LAN", "Offline") IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_WLAN", "Offline") EndIf Else IniWrite(@ScriptDir & "\status.ini", "Server status", "Devices Online", "Yes") If $mylaptop Then IniWrite(@ScriptDir & "\status.ini", "Devices", "My_Laptop", "Online") Else Sleep(60000) If $mylaptop = 0 Then IniWrite(@ScriptDir & "\status.ini", "Devices", "My_Laptop", "Offline") EndIf EndIf If $mylaptop2 Then IniWrite(@ScriptDir & "\status.ini", "Devices", "My_Laptop", "Online") Else Sleep(60000) If $mylaptop2 = 0 Then IniWrite(@ScriptDir & "\status.ini", "Devices", "My_Laptop", "Offline") EndIf EndIf If $macilan Then IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_LAN", "Online") Else Sleep(60000) If $macilan = 0 Then IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_LAN", "Offline") EndIf EndIf If $maciwlan Then IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_WLAN", "Online") Else Sleep(60000) If $maciwlan = 0 Then IniWrite(@ScriptDir & "\status.ini", "Devices", "maci_WLAN", "Offline") EndIf EndIf EndIf $status = IniRead(@ScriptDir & "\status.ini", "Server status", "Devices Online", "NotFound") $scheduler = IniRead(@ScriptDir & "\status.ini", "Server status", "Scheduler", "NotFound") If ProcessExists("uTorrent.exe") Then ; Sleep(10000) If $status = "Yes" And $scheduler = "Disabled" Then WinActivate("[CLASS:µTorrent4823DF041B09]", "") Send("{CTRLDOWN}") ;sleep(200) Send("p") ;sleep(200) Send("{CTRLUP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{tab}") ;sleep(200) Send("{space}") Send("{enter}") IniWrite(@ScriptDir & "\status.ini", "Server status", "Scheduler", "Enabled") $logstatus = "Scheduler Enabled" If $maciwlan Then $logstatus = $logstatus & "... Maci Wlan Online" If $macilan Then $logstatus = $logstatus & "... Maci Lan Online" If $mylaptop Or $mylaptop2 Then $logstatus = $logstatus & "... My_Laptop Online" If $IP5 Then $logstatus = $logstatus & "... IP5 Online" If $IP6 Then $logstatus = $logstatus & "... IP6 Online" If $IP7 Then $logstatus = $logstatus & "... IP7 Online" If $IP8 Then $logstatus = $logstatus & "... IP8 Online" If $IP9 Then $logstatus = $logstatus & "... IP9 Online" If $IP10 Then $logstatus = $logstatus & "... IP10 Online" $tSystem = _Date_Time_GetSystemTime() $tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem)) IniWrite(@ScriptDir & "\log.ini", "Server log", _Date_Time_SystemTimeToDateTimeStr($tLocal), $logstatus) Local $update = InetGetSize("http://downloads.sourceforge.net/scarangel/ipfilter.rar") $size = FileGetSize(@AppDataDir & "\uTorrent\ipfilter.rar") If $update = $size Then WinSetState("[CLASS:µTorrent4823DF041B09]", "", @SW_MINIMIZE) Else WinActivate("[CLASS:µTorrent4823DF041B09]", "") Send("{ALT}") Send("{F}") Send("{X}") Send("{Y}") ProcessWaitClose("uTorrent.exe") Run(@AppDataDir & "\uTorrent\µpdater.bat", @AppDataDir & "\uTorrent\") $tSystem = _Date_Time_GetSystemTime() $tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem)) IniWrite(@ScriptDir & "\log.ini", "Server log", _Date_Time_SystemTimeToDateTimeStr($tLocal), "Update done") EndIf EndIf Else ProcessWait("uTorrent.exe") EndIf If ProcessExists("uTorrent.exe") Then ; Sleep(10000) If $status = "No" And $scheduler = "Enabled" Then WinActivate("[CLASS:µTorrent4823DF041B09]", "") Send("{CTRLDOWN}") ;sleep(200) Send("p") ;sleep(200) Send("{CTRLUP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") Send("{UP}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{Down}") ;sleep(200) Send("{tab}") ;sleep(200) Send("{space}") Send("{enter}") IniWrite(@ScriptDir & "\status.ini", "Server status", "Scheduler", "Disabled") $logstatus = "Scheduler Disabled" $tSystem = _Date_Time_GetSystemTime() $tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem)) IniWrite(@ScriptDir & "\log.ini", "Server log", _Date_Time_SystemTimeToDateTimeStr($tLocal), $logstatus) Local $update = InetGetSize("http://downloads.sourceforge.net/scarangel/ipfilter.rar") $size = FileGetSize(@AppDataDir & "\uTorrent\ipfilter.rar") If $update = $size Then WinSetState("[CLASS:µTorrent4823DF041B09]", "", @SW_MINIMIZE) Else WinActivate("[CLASS:µTorrent4823DF041B09]", "") Send("{ALT}") Send("{F}") Send("{X}") Send("{Y}") ProcessWaitClose("uTorrent.exe") Run(@AppDataDir & "\uTorrent\µpdater.bat", @AppDataDir & "\uTorrent\") $tSystem = _Date_Time_GetSystemTime() $tLocal = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem)) IniWrite(@ScriptDir & "\log.ini", "Server log", _Date_Time_SystemTimeToDateTimeStr($tLocal), "Update done") EndIf EndIf Else ProcessWait("uTorrent.exe") EndIf Sleep(60000) WEnd The answer for pinging an IP (e.g. 192.168.0.111) is: Destination host unreachable. This should still be "ping = 0" according to the autoit help file: Return Value: 0 if host is not pingable or other network errors occurred and sets the @error flag to non-zero. @error: 1 = Host is offline 2 = Host is unreachable 3 = Bad destination 4 = Other errors I also tried "if ping 192.168.0.111 = 0 or 1 or 2 or 3 or 4 then" but that didn't work either. Any ideas? Thanks !
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now