Jump to content

Run a Ping to multiple address at the same time


 Share

Recommended Posts

Hi Folks,

I want to create a tray app that will ping multiple locations at the same time and also log the results to seperate log files.

So Ping headoffice & Ping branchoffice - end up with headoffice.log and branchoffice.log

I have created the files the only problem is the only way currently I can do it is to run the exe twice with different IP addresses.

Is there a way to run commands simulatanously from within an exe.

I don't want to do ping location1 then Ping location2 as then the ping logs will have gaps.

Cheers

Michael

$ans = ping($ping,250) ; ping our address

if $ans Then ;if successfull then

_FileWriteLog($Filename," " & "Success" & " Time to ping:" & $ans & "ms",-1)

;FileWrite($file, _nowtime() & " " & "Success" & " Time to ping:" & $ans & "ms" & @CRLF) ;write to file

$Success = $Success + 1

$countfailed = 0

else ;if ping fails then

_FileWriteLog($Filename," " & "Failed Error:" & @error,-1)

;Filewrite($file, _nowtime() & " " & "Failed Error:" & @error & @CRLF); write this to file

$Failed = $Failed + 1

$countfailed = $countfailed + 1

if $countfailed = 20 Then

Run("eventcreate /T ERROR /ID 0999 /L Application /SO ITFocus /D " & _

Chr(34) & "20 Failed pings to location: "& $Location &Chr(34), "", @SW_HIDE, 2)

$countfailed = 0

EndIf

endIf

Link to comment
Share on other sites

one way

#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#region ### START Koda GUI section ### Form=
Global $hGUI = GUICreate("Ping Test", 551, 443, 192, 124, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT))
Global $Edit1 = GUICtrlCreateEdit("", 8, 16, 529, 177)
GUICtrlSetLimit(-1, 9999999)
Global $Edit2 = GUICtrlCreateEdit("", 10, 201, 529, 177)
GUICtrlSetLimit(-1, 9999999)
Global $Button1 = GUICtrlCreateButton("Press to Start", 224, 392, 105, 33, BitOR($BS_CENTER, $WS_GROUP), $WS_EX_STATICEDGE)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Ping()

    EndSwitch
WEnd

Func _Ping()
    Local $gFile = "C:\Google.txt"
    Local $bFile = "C:\Bing.txt"
    _FileCreate($gFile) ;clear file
    _FileCreate($bFile) ;clear file
    GUICtrlSetData($Button1, "Ping in Progress")
    Local $PID1 = Run(@ComSpec & " /c ping -n 6 www.google.com > " & $gFile, "C:\", @SW_HIDE)
    Local $PID2 = Run(@ComSpec & " /c ping -n 6 www.bing.com > " & $bFile, "C:\", @SW_HIDE)
    While 1
        $gData = FileRead($gFile)
        $bData = FileRead($bFile)
        If GUICtrlRead($Edit1) <> $gData Then GUICtrlSetData($Edit1, $gData)
        If GUICtrlRead($Edit2) <> $bData Then GUICtrlSetData($Edit2, $bData)
        If Not ProcessExists($PID1) And Not ProcessExists($PID2) Then ExitLoop
    WEnd
    GUICtrlSetData($Button1, "Press to Start")
EndFunc   ;==>_Ping
Edited by Varian
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...