microbious Posted June 24, 2009 Share Posted June 24, 2009 I am trying to create (in fact its already working) little program that would continuously ping primary host to assure that it is connected to internet. If server ping gets to 0 then it will write error into log file saying it did not get response from 1st server at @time @min. Right after that it will (it should but it doesnt) ping second specified server and do same thing, if 2nd address ping is 0 then Error goes to log saying 2nd server no response. Then it will start from the beginning from 1st server (loop) continuously writing log file. Reason why i need this is i recently had frequent internet signal drops and i am trying to track down time when it happens so i could call Comcast and tell them when and for how long and how many times. SO here is the code. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> FileDelete ("Log.txt") GUICreate("",200,100) GUISetState(@SW_SHOW) $log = GUICtrlCreateEdit('',100,0,100,100) $Addressinput = GUICtrlCreateInput("Primary host",0,0,100,20) $Addressinput2 = GUICtrlCreateInput("Backup host",0,20,100,20) $Timeinput = GUICtrlCreateInput("15000",0,40,40,20) GUICtrlCreateLabel ("1000=1sec",40,43,60) $Button = GUICtrlCreateButton ("Poke'em",0,60,100,40) While 1 $nMsg = GUIGetMsg() Switch $nMsg case $Button While 1 $Address = GUICtrlRead($Addressinput) $Address2 = GUICtrlRead($Addressinput2) $Time = GUICtrlRead($Timeinput) $ping = Ping ($Address) GUICtrlSetData ($log,$ping & @CRLF) Sleep ($Time) If $ping <= 0 Then GUICtrlSetData ($log,"No response from 1st address at "&@HOUR &':'& @MIN & @CRLF) $output = GUICtrlRead ($log) FileWrite ("Log.txt",$output) MsgBox (0,'','1') ;Sleep ($time) $ping2 = Ping ($Address2) ;GUICtrlSetData ($log,$ping2 & @CRLF) GUICtrlSetData ($log,"No response from 2nd address at "&@HOUR &':'& @MIN & @CRLF) $output2 = GUICtrlRead ($log) FileWrite ("Log.txt",$output2) MsgBox (0,'','2') ;Sleep ($time) EndIf WEnd Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd exit Problem with this code is that its not trying to connect to backup serer (HOST) to ping it and i am stuck trying to figure out best way for this to work. Please help me solve it i am still new with these If's stuff. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 24, 2009 Moderators Share Posted June 24, 2009 Gettingsmarter,Take a look at this:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_On_Exit") FileDelete("Log.txt") GUICreate("", 400, 100) GUISetState(@SW_SHOW) $log = GUICtrlCreateEdit('', 100, 0, 300, 100) $Addressinput = GUICtrlCreateInput("Primary host", 0, 0, 100, 20) $Addressinput2 = GUICtrlCreateInput("Backup host", 0, 20, 100, 20) $Timeinput = GUICtrlCreateInput("15000", 0, 40, 40, 20) GUICtrlCreateLabel("1000=1sec", 40, 43, 60) $Button = GUICtrlCreateButton("Poke'em", 0, 60, 100, 40) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button While 1 $Address = GUICtrlRead($Addressinput) $Time = GUICtrlRead($Timeinput) $ping = Ping($Address, $Time) GUICtrlSetData($log, $ping & @CRLF) If $ping = 0 Then GUICtrlSetData($log, "No response from 1st address at " & @HOUR & ':' & @MIN & @CRLF) $output = GUICtrlRead($log) FileWrite("Log.txt", $output) ; Try second server $Address2 = GUICtrlRead($Addressinput2) $ping2 = Ping($Address2, $Time) If $ping2 = 0 Then GUICtrlSetData($log, "No response from 2nd address at " & @HOUR & ':' & @MIN & @CRLF) $output2 = GUICtrlRead($log) FileWrite("Log.txt", $output2) EndIf EndIf WEnd Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit Func _On_Exit() Exit EndFuncI added another If section to cover the second Ping. I also increased the GUI size so I could see what was happening and gave you a Hotkey to exit (Escape). I think it should work for you now.Ask if anything is unclear.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
microbious Posted June 24, 2009 Author Share Posted June 24, 2009 doesnt work. If 1st is 0 then its not going to next one, it keeps retrying 1st one, even log says that. Thanks for trying to help. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 24, 2009 Moderators Share Posted June 24, 2009 Gettingsmarter, Are you sure? It works for me - just as the code says it will! Here is my Log.txt file:No response from 1st address at 09:32 No response from 2nd address at 09:32 No response from 1st address at 09:32 No response from 2nd address at 09:32 M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
microbious Posted June 24, 2009 Author Share Posted June 24, 2009 Gettingsmarter, Are you sure? It works for me - just as the code says it will! Here is my Log.txt file:No response from 1st address at 09:32 No response from 2nd address at 09:32 No response from 1st address at 09:32 No response from 2nd address at 09:32 M23 Something is wrong with ur code, no matter what time i set it keeps pinging them every have second.\Hosts will probably ban my IP after me doing it fir a while Trying to figure out but it all looks good Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 24, 2009 Moderators Share Posted June 24, 2009 (edited) Gettingsmarter,My fault - I used your delay variable ($Timeinput) as the time out for the ping itself and not the delay between them. How much of a gap would you like between the 2 ping attempts and before retrying? M23Edit: This code waits for the set delay between each ping attempt. I hope it will save your connection! :-)expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_On_Exit") FileDelete("Log.txt") GUICreate("", 400, 100) GUISetState(@SW_SHOW) $log = GUICtrlCreateEdit('', 100, 0, 300, 100) $Addressinput = GUICtrlCreateInput("Primary host", 0, 0, 100, 20) $Addressinput2 = GUICtrlCreateInput("Backup host", 0, 20, 100, 20) $Timeinput = GUICtrlCreateInput("15000", 0, 40, 40, 20) GUICtrlCreateLabel("1000=1sec", 40, 43, 60) $Button = GUICtrlCreateButton("Poke'em", 0, 60, 100, 40) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button While 1 $Address = GUICtrlRead($Addressinput) $Time = GUICtrlRead($Timeinput) $ping = Ping($Address, $Time) GUICtrlSetData($log, $ping & @CRLF) If $ping = 0 Then GUICtrlSetData($log, "No response from 1st address at " & @HOUR & ':' & @MIN & @CRLF) $output = GUICtrlRead($log) FileWrite("Log.txt", $output) $Begin = TimerInit() While 1 If TimerDiff($Begin) > $Time Then ExitLoop If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd ; Try second server $Address2 = GUICtrlRead($Addressinput2) $ping2 = Ping($Address2, $Time) If $ping2 = 0 Then GUICtrlSetData($log, "No response from 2nd address at " & @HOUR & ':' & @MIN & @CRLF) $output2 = GUICtrlRead($log) FileWrite("Log.txt", $output2) EndIf EndIf $Begin = TimerInit() While 1 If TimerDiff($Begin) > $Time Then ExitLoop If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd WEnd Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit Func _On_Exit() Exit EndFuncM23 Edited June 24, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
microbious Posted June 25, 2009 Author Share Posted June 25, 2009 (edited) Thanks Hey how can i limit the edit box entry's coming from GUICtrlSetData($log, $ping & @CRLF,'List') I tried $writelog = GUICtrlSetData($log, $ping & @CRLF,'List') GUICtrlSetLimit($writelog,10) but that didnt work, it keeps adding line after line to the log window and in the end it would be just to much to look at and maybe crash Plus i cant get out of the loop by pressing X in the top right if the programs window. I tried creating button Case with Exit but that didnt help, its just not doing anything unless script is paused. Edited June 25, 2009 by Gettingsmarter Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 25, 2009 Moderators Share Posted June 25, 2009 Gettingsmarter, Use the Hotkey to get out of the app if the [X] does not work - I did tell you: ;-) I also ... gave you a Hotkey to exit (Escape)As to limiting the edit, see if this does what you want. It starts by appending to the edit as before, but then clears the edit after 10 successful pings. It also appends any unsuccessful attempts, but only writes the unsuccessful ones to the log.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_On_Exit") FileDelete("Log.txt") GUICreate("", 400, 200) GUISetState(@SW_SHOW) $log = GUICtrlCreateEdit('', 100, 0, 300, 200) $Addressinput = GUICtrlCreateInput("Primary host", 0, 0, 100, 20) $Addressinput2 = GUICtrlCreateInput("Backup host", 0, 20, 100, 20) $Timeinput = GUICtrlCreateInput("15000", 0, 40, 40, 20) GUICtrlCreateLabel("1000=1sec", 40, 43, 60) $Button = GUICtrlCreateButton("Poke'em", 0, 60, 100, 40) $iCount = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button While 1 $Address = GUICtrlRead($Addressinput) $Time = GUICtrlRead($Timeinput) $ping = Ping($Address, $Time) $iCount += 1 If $iCount < 11 Then GUICtrlSetData($log, $ping & @CRLF, 1) Else GUICtrlSetData($log, $ping & @CRLF) $iCount = 0 EndIf If $ping = 0 Then $output = "No response from 1st address at " & @HOUR & ':' & @MIN & @CRLF GUICtrlSetData($log, $output, 1) FileWrite("Log.txt", $output) $Begin = TimerInit() While 1 If TimerDiff($Begin) > $Time Then ExitLoop If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd ; Try second server $Address2 = GUICtrlRead($Addressinput2) $ping2 = Ping($Address2, $Time) If $ping2 = 0 Then $output2 = "No response from 2nd address at " & @HOUR & ':' & @MIN & @CRLF GUICtrlSetData($log, $output2, 1) FileWrite("Log.txt", $output2) EndIf EndIf $Begin = TimerInit() While 1 If TimerDiff($Begin) > $Time Then ExitLoop If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit WEnd WEnd Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit Func _On_Exit() Exit EndFunc Just look carefully at the GUICtrlSetData statements to see how it works. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
microbious Posted June 25, 2009 Author Share Posted June 25, 2009 Thanks. I will rewrite step by step your examples and am sure i will learn allot from them. Only way i learn autoit is taking other ppls examples and write them one line at the time to better understand whats going on Thanks a bunch ! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 26, 2009 Moderators Share Posted June 26, 2009 Gettingsmarter, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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