Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; on crée un petit formulaire
$Form1 = GUICreate("Ping", 256, 120, -1, -1, $DS_MODALFRAME)
$Label1 = GUICtrlCreateLabel("Adresse a pinger", 8, 24, 83, 17)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 104, 24, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
$Button1 = GUICtrlCreateButton("Go !", 20, 56, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Sortir", 160, 56, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW, $Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $button2 ; on sort
Exit
Case $Button1 ; on récupere l'ip et on la ping
_ping(_GUICtrlIpAddress_Get($IPAddress1))
EndSwitch
WEnd
Func _ping($IP)
; on met un petit écran d'attente
$Form2 = GUICreate("Patience", 229, 94, -1, -1, $DS_MODALFRAME)
$Label2 = GUICtrlCreateLabel("Ping en cours." & @CRLF & "Veuillez patienter quelques instants ...", 24, 16, 240, 34)
GUISetState(@SW_SHOW, $Form2)
Local $erreur = False
Local $blocs[5], $i
; on check l'IP
$blocs = StringSplit($IP, ".")
For $i = 1 To 4
If $blocs[$i] < 0 Or $blocs[$i] > 255 Then $erreur = True
ConsoleWrite($blocs[$i] & @CRLF)
Next
If $erreur = False Then ; si c'est bon, on ping
RunWait(@ComSpec & " /c ping " & $IP & " > " & "c:\WINDOWS\ping.txt", "", @SW_HIDE)
GUISetState(@SW_HIDE, $Form2) ; on enleve l'écran d'attente
If @error = 0 Then ; et on affiche le résultat (Ok ou erreur)
MsgBox(0, "Ping", "Ping éffectué." & @CRLF _
& "Le résultat du ping est visible dans le fichier :" & @CRLF _
& "c:\WINDOWS\ping.txt")
Else
MsgBox(0, "Ping", "Ca a pas marché !")
EndIf
Else ; si c'est pas bon, on l'indique
MsgBox(0, "Ping", "Format de l'adresse IP non valide")
EndIf
EndFunc