#include <Constants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#Region ### START Koda GUI section ### Form=C:\bat\autoit\koda_1.7.0.1\Forms\ping_trace.kxf
Opt("GUIOnEventMode", 1)
$Form1_1 = GUICreate("Trace & ping", 557, 439, 192, 114)
$p_size = GUICtrlCreateInput("64", 448, 16, 89, 21)
$Label1 = GUICtrlCreateLabel("Packet Size (bytes)", 320, 16, 119, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$host = GUICtrlCreateInput("", 8, 32, 241, 32)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Ping && Trace", 64, 72, 121, 33, $WS_GROUP)
$ping_area = GUICtrlCreateEdit("", 0, 136, 555, 129)
GUICtrlSetColor(-1, 0x000080)
$trace_area = GUICtrlCreateEdit("", 0, 296, 555, 137)
GUICtrlSetColor(-1, 0x000080)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH)
$Label2 = GUICtrlCreateLabel("Ping", 16, 112, 31, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Trace", 16, 272, 40, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$p_count = GUICtrlCreateInput("30", 448, 40, 89, 21)
$Label4 = GUICtrlCreateLabel("Count of packets", 320, 40, 103, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUICtrlSetOnEvent($button1, "go")
$p_timeout = GUICtrlCreateInput("1000", 448, 64, 89, 21)
$Label5 = GUICtrlCreateLabel("Ping timeout (msec)", 320, 64, 121, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$t_timeout = GUICtrlCreateInput("1000", 448, 88, 89, 21)
$Label6 = GUICtrlCreateLabel("Trace timeout (msec)", 312, 88, 130, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("Host", 16, 8, 38, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$ping = ""
$trace = ""
While 1
Sleep(10)
WEnd
Func go()
$irun_ping = Run(@ComSpec & ' /c ping ' & GUICtrlRead($host) & ' -n ' & GUICtrlRead($p_count) & ' -l ' & GUICtrlRead($p_size) & ' -w ' & GUICtrlRead($p_timeout), '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$irun_trace = Run(@ComSpec & ' /c tracert ' & GUICtrlRead($host) & ' -w ' & GUICtrlRead($t_timeout), '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$timer = TimerInit()
$ok = 0
While 1
$ping = StdoutRead($irun_ping)
if $ping <> "" Then
GUICtrlSetData($ping_area, GUICtrlRead($ping_area) & _StringOEM2ANSI($ping))
_GUICtrlEdit_LineScroll($ping_area, 0, _GUICtrlEdit_GetLineCount($ping_area))
EndIf
if StringInStr($ping, 'Average') Then $ok += 1
$trace = StdoutRead($irun_trace)
if $trace <> "" Then
GUICtrlSetData($trace_area, GUICtrlRead($trace_area) & _StringOEM2ANSI($trace))
_GUICtrlEdit_LineScroll($trace_area, 0, _GUICtrlEdit_GetLineCount($trace_area))
EndIf
if StringInStr($trace, 'complete') Then $ok += 1
Sleep(100)
If $ok = 2 Then ExitLoop
WEnd
EndFunc
Func _exit()
Exit
EndFunc
Func _StringOEM2ANSI($strText)
Local $sBuffer = DllStructCreate("char[" & StringLen($strText)+1 & "]")
Local $aRet = DllCall("User32.dll", "int", "OemToChar", "str", $strText, "ptr", DllStructGetPtr($sBuffer))
If Not IsArray($aRet) Then Return SetError(1, 0, '') ; ошибка DLL
If $aRet[0] = 0 Then Return SetError(2, $aRet[0], '') ; ошибка функции
Return StringRegExpReplace(DllStructGetData($sBuffer, 1), "\r\n", @CRLF)
EndFunc
Func bar_start()
EndFunc