Jump to content

Ping = me frustrated :-)


TheBG
 Share

Recommended Posts

Hello all,

I don't know where i'm going wrong on this one.. I can;t seem to get his to work.

in short. I'm creating an application to check network status of some servers we have here. I simply want to run the app and have it ping the servers every 5 minutes (poor man's "Whats up" app). the form is simple. it have 2 buttons with server names, they highlight green or red depending on the ping command.

so far, it only works if everything is pinging, as soon as I take one of the network, the app no longer works.

Also, I would appreciate it if someone could show me how to put a timer on this, so, it pings the servers every 5 minutes.

#include <GUIConstants.au3>


$OKRightDlg = GUICreate("Dialog", 357, 196, 265, 187)
GUISetIcon("D:\009.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 257, 185)
$AGEKEYS3 = GUICtrlCreateButton("Age-Keys3", 24, 24, 129, 33, 0)
$AGEMONVM1 = GUICtrlCreateButton("Age-MON-VM1", 24, 64, 129, 33, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Exit = GUICtrlCreateButton("&Exit", 272, 48, 75, 25, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            ExitPressed()           
    EndSwitch
    
    $AGEMONVM1 = Ping("age-mon-vm1", 1000)
    If $AGEMONVM1 Then
        GUICtrlSetBkColor($AGEMONVM1, 0x009900)
    Else
        GUICtrlSetBkColor($AGEMONVM1, 0xCC0000)
    EndIf
    $AGEKEYS3 = Ping("age-keys3", 1000)
    If $AGEKEYS3 Then
        GUICtrlSetBkColor($AGEKEYS3, 0x009900)
    Else
        GUICtrlSetBkColor($AGEKEYS3, 0xCC0000)
    EndIf
WEnd


; Cancel then Exit the program
Func ExitPressed()
  Local $Exit
    $Exit = MsgBox(262452,"Cancel","Are you sure you want to Cancel and then Exit?")
    If $Exit = 6 Then
    Exit
    Endif
EndFunc
Link to comment
Share on other sites

  • Developers

Look at the used variable names: You override the Button Control Handle with the result of Ping.

$AGEMONVM1 = Ping("age-mon-vm1", 1000)
    If $AGEMONVM1 Then
        GUICtrlSetBkColor($AGEMONVM1, 0x009900)
    Else
        GUICtrlSetBkColor($AGEMONVM1, 0xCC0000)
    EndIf

The timer requirement could be solved with the Adlib function.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Variation on Jos' idea with the variable names fixed and no AdLib

#include <GUIConstants.au3>


$OKRightDlg = GUICreate("Dialog", 357, 196, 265, 187)
;GUISetIcon("D:\009.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 257, 185)
$Btn_AGEKEYS3 = GUICtrlCreateButton("Age-Keys3", 24, 24, 129, 33, 0)
$Btn_AGEMONVM1 = GUICtrlCreateButton("Age-MON-VM1", 24, 64, 129, 33, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Exit = GUICtrlCreateButton("&Exit", 272, 48, 75, 25, 0)
_PingIt()
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            ExitPressed()
    Case $Btn_AGEKEYS3
        MsgBox(0, "Ping Result", Ping("www.autoitscript.com"))
    Case $Btn_AGEMONVM1
        MsgBox(0, "Ping Result", Ping("www.google.com"))
    EndSwitch
    If (NOT Mod(@Min, 5)) AND @SEC = 0 Then _PingIt()
WEnd

Func _PingIt()
    If Ping("www.google.com", 1000) Then
    ;If $AGEMONVM1 Then
        GUICtrlSetBkColor($Btn_AGEMONVM1, 0x009900)
    Else
        GUICtrlSetBkColor($Btn_AGEMONVM1, 0xCC0000)
    EndIf
    If Ping("www.autoitscript.com", 1000) Then
    ;If $AGEKEYS3 Then
        GUICtrlSetBkColor($Btn_AGEKEYS3, 0x009900)
    Else
        GUICtrlSetBkColor($Btn_AGEKEYS3, 0xCC0000)
    EndIf
EndFunc
; Cancel then Exit the program
Func ExitPressed()
  Local $Exit
    $Exit = MsgBox(262452,"Cancel","Are you sure you want to Cancel and then Exit?")
    If $Exit = 6 Then
    Exit
    Endif
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

AWESOME! thanks for the help.

So, does this constantly ping, or only pings every so often?

It would be great if it only pings like every 5 minutes.

Variation on Jos' idea with the variable names fixed and no AdLib

#include <GUIConstants.au3>


$OKRightDlg = GUICreate("Dialog", 357, 196, 265, 187)
;GUISetIcon("D:\009.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 257, 185)
$Btn_AGEKEYS3 = GUICtrlCreateButton("Age-Keys3", 24, 24, 129, 33, 0)
$Btn_AGEMONVM1 = GUICtrlCreateButton("Age-MON-VM1", 24, 64, 129, 33, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Exit = GUICtrlCreateButton("&Exit", 272, 48, 75, 25, 0)
_PingIt()
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Exit
            ExitPressed()
    Case $Btn_AGEKEYS3
        MsgBox(0, "Ping Result", Ping("www.autoitscript.com"))
    Case $Btn_AGEMONVM1
        MsgBox(0, "Ping Result", Ping("www.google.com"))
    EndSwitch
    If (NOT Mod(@Min, 5)) AND @SEC = 0 Then _PingIt()
WEnd

Func _PingIt()
    If Ping("www.google.com", 1000) Then
    ;If $AGEMONVM1 Then
        GUICtrlSetBkColor($Btn_AGEMONVM1, 0x009900)
    Else
        GUICtrlSetBkColor($Btn_AGEMONVM1, 0xCC0000)
    EndIf
    If Ping("www.autoitscript.com", 1000) Then
    ;If $AGEKEYS3 Then
        GUICtrlSetBkColor($Btn_AGEKEYS3, 0x009900)
    Else
        GUICtrlSetBkColor($Btn_AGEKEYS3, 0xCC0000)
    EndIf
EndFunc
; Cancel then Exit the program
Func ExitPressed()
  Local $Exit
    $Exit = MsgBox(262452,"Cancel","Are you sure you want to Cancel and then Exit?")
    If $Exit = 6 Then
    Exit
    Endif
EndFunc

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...