JiBe Posted February 14, 2015 Share Posted February 14, 2015 Hello to all, I saw many people looking for a solution to Ping multiple devices and quickly. that is why I propose a solution that I use. the principle is simple: -a list of IP address in a table. -then execution of all Ping from array -recovery of the return via a Windows message. thats all.the recovery of the return via a SendMessage to not beforced to wait for a return.the return due it to an event. I let you discover and make me your comment. excused my English, I'm French! :-) expandcollapse popup#include-once #include <AutoItConstants.au3> #pragma compile(AutoItExecuteAllowed, True) ; #INDEX# ======================================================================================================================= ; Title .........: Mping_UDF ; AutoIt Version : 3.3.12.0 ; Language ......: French ; Description ...: ; ; Author(s) .....: Joseph Barone 2015 ; Exe(s) ........: aucun ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _Mping ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; __StartLine ; __StartScript (non utilisé) ; __WM_PING_Receive ; __Result ; =============================================================================================================================== ; variable et declaration ;Global $j = 0 ;Global $count = 0 Global $ProcessCount = 0 Global $FuncCallBack = "" Global $GuiHwnd = GUICreate("GetTheMessage") Global Const $WM_COMMAND = 0x0111 Global Const $WM_PING = $WM_COMMAND + 0xFF GUIRegisterMsg($WM_PING, "__WM_MESSAGE_Receive") ;tableau a definir et a remplir avec les IP/nom DNS. ; index [0][x] = adresse Ip ou Nom DNS ; index [1][x] = resultat du Ping 0 = Nok, 1 ou plus = Ok valeur du timeout ; index [2][x] = handle du process 'Ping' (Usage interne) Global $MapIP[3][2] ;=================== Exemple d'utilisation =================== ;~ ;#include "_MultiPing.au3" ;~ ; index [0][x] = adresse Ip ou Nom DNS ;~ ; index [1][x] = resultat du Ping 0 = Nok, 1 ou plus = Ok valeur du timeout ;~ ; index [2][x] = handle du process 'Ping' (Usage interne) ;~ Dim $MesIP[3][10] = [["192.168.0.254","192.168.1.3","192.168.2.221","8.8.8.8","8.8.4.4","free.fr","google.cn","nosite.fr","orange.fr","192.168.1.250"],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]] ;~ $MapIP = $MesIP ;~ ;~ _Mping($MapIP) ;~ ConsoleWrite("je m'arrete 30 secondes, je suis fatigué!!"&@CRLF) ;~ Sleep(30000) ;~ ConsoleWrite("je reprends, je me suis assez reposé!!"&@CRLF) ;~ ; Juste pour montrer que la boite de message n'à pas bloqué le script. ;~ For $i = 1 To 1000 Step 30 ;~ Beep($i, 50) ;~ Next ;~ For $i = 1000 To 1 Step -30 ;~ Beep($i, 50) ;~ Next ;~ ;définition de la fonction Callback ;~ $FuncCallBack = "Result" ;~ _Mping($MapIP) ;~ ConsoleWrite("je m'arrete 30 secondes, je suis fatigué!!"&@CRLF) ;~ Sleep(30000) ;~ ConsoleWrite("je reprends, je me suis assez reposé!!"&@CRLF) ;~ ;Function callback de test ;~ Func Result($Process) ;~ ConsoleWrite("Le meilleur Ping de l'ip:"&$MapIP[0][$Process]&" resultat:"&$MapIP[1][$Process]&@CRLF) ;~ EndFunc ;=================== Fin de l'Exemple =================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _Mping($ArrayIp,$Limit = 10) ; Description ...: Ping plusieurs IP en simultané ; Parameters ....: $ArrayIp doit contenir: ; index[0] = l'ip a testé ; index[1] = le resultat du Ping 0 = Nok, 1 ou plus = Ok valeur du timeout ; index[2] = handle du process 'Ping' (Usage interne) ; $Limit = Limite le nombre de processus simultané. par défaut 10 processus ; Return values .: voir l'index[1] ; Author ........: Joseph Barone ; Modified.......: ; =============================================================================================================================== Func _Mping($ArrayIp,$Limit = 10) if UBound($ArrayIp,1)<>3 Then ConsoleWrite("le tableau n'est pas au bon format"&@CRLF) Return EndIf ConsoleWrite("le tableau est au bon format"&@CRLF) Local $i = 0 While 1 If $Limit > $ProcessCount Then ; Parametre a fournir avec le message (ici, l'index du tableau pour connaitre a qui appartient le retour)------------------------------------------------| ; Parametre a fournir avec le message (ici, la fonction ping pour recuperer le timeout)---------------------------------------| | ; Message a envoyé, peut etre un message Windows ou personnel (ici, messge pour le ping)-----| | | ; Handle utilisé pour les retour des message----------------------------| | | | ; _____|____ _____|____ ________|________ __|_ $cmd = "DllCall('user32.dll', 'lresult', 'SendMessage', 'hwnd', "&$GuiHwnd&", 'uint',"&$WM_PING&", 'wparam', ping('"&$ArrayIp[0][$i]&"'), 'lparam', "&$i&")" $ProcessCount += 1 __StartLine($cmd,$i) $i += 1 If UBound($ArrayIp,2)=$i Then ExitLoop Else Sleep(5) EndIf WEnd EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: __StartLine($Line,$process) ; Description ...: Execute un process Ping ; Parameters ....: $Line = ligne de commande Ping a executé ; $process = Index du process dans le tableau ; Return values .: voir l'index[1] ; Author ........: Joseph Barone ; Modified.......: ; =============================================================================================================================== Func __StartLine($Line,$process) If @Compiled Then ; Si le script est compilé, AutoIt.exe n'est peut être pas disponible. Donc on utilise le script compilé lui même. $MapIP[2][$process] = Run(@ScriptFullPath & ' /ErrorStdOut /AutoIt3ExecuteLine "'&$Line&'"',"", -1, $STDOUT_CHILD) Else $MapIP[2][$process] = Run(@AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteLine "'&$Line&'"',"", -1, $STDOUT_CHILD) EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: __StartScript($Script,$process) ; Description ...: Execute un Script ; Parameters ....: $Script = Script au foramt au3 ou a3x ; $process = Index du process dans le tableau ; Return values .: voir l'index[1] ; Author ........: Joseph Barone ; Modified.......: ; =============================================================================================================================== Func __StartScript($Script,$process) If @Compiled Then ; Si le script est compilé, AutoIt.exe n'est peut être pas disponible. Donc on utilise le script compilé lui même. $MapIP[2][$process] = Run(@ScriptFullPath & ' /ErrorStdOut /AutoIt3ExecuteScript "'&$Script&'"',"", -1, $STDOUT_CHILD) Else $MapIP[2][$process] = Run(@AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteScript "'&$Script&'"',"", -1, $STDOUT_CHILD) EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: __WM_MESSAGE_Receive($hWnd, $iMsg, $wParam, $lParam) ; Description ...: Callback du flux message ; Parameters ....: $hWnd = handle ; $iMsg = Message reçu ; $wParam = Information additionnel pour un message specifique ; $lParam = Information additionnel pour un message specifique ; Return values .: ; Author ........: Joseph Barone ; Modified.......: ; =============================================================================================================================== Func __WM_MESSAGE_Receive($hWnd, $iMsg, $wParam, $lParam) Local $Param1 = Dec(StringTrimLeft ($wParam, 2 ));LoWord Local $Param2 = Dec(StringTrimLeft ($lParam, 2 )) ;ConsoleWrite(UBound($MapIP,1)&" "&UBound($MapIP,2)&" "&$Param2&@CRLF) if $iMsg = $WM_PING Then If UBound($MapIP,2) > $Param2 Then $MapIP[1][$Param2] = $Param1 $ProcessCount -= 1 If $FuncCallBack = "" Then Execute('__Result('&$Param2&')') Else Execute($FuncCallBack&'('&$Param2&')') EndIf EndIf EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: __Result($Process) ; Description ...: affiche le resultat d'un ping ; Parameters ....: $Process = Index du process dans le tableau ; Return values .: ; Author ........: Joseph Barone ; Modified.......: ; =============================================================================================================================== Func __Result($Process) ConsoleWrite("Ping de l'ip:"&$MapIP[0][$Process]&" resultat:"&$MapIP[1][$Process]&@CRLF) EndFunc FastMultiPing.zip pintas 1 Link to comment Share on other sites More sharing options...
pintas Posted April 23, 2018 Share Posted April 23, 2018 HI! Thanks for this. Just one quick question... If i want to extract the positive results to an array, and the '0' pings to another array, what should i do? Link to comment Share on other sites More sharing options...
Gianni Posted April 24, 2018 Share Posted April 24, 2018 21 hours ago, pintas said: ... If i want to extract the positive results to an array, and the '0' pings to another array, what should i do? an alternative can be this other MultiPing function (https://www.autoitscript.com/forum/topic/156395-versatile-multi-ping/). It accepts a list of devices to ping and returns an array loaded with all ping results. No claim of comparison with this udf here, only one more possibility that maybe is easyer for your purpose. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
pintas Posted April 24, 2018 Share Posted April 24, 2018 1 hour ago, Chimp said: an alternative can be this other MultiPing function (https://www.autoitscript.com/forum/topic/156395-versatile-multi-ping/). It accepts a list of devices to ping and returns an array loaded with all ping results. No claim of comparison with this udf here, only one more possibility that maybe is easyer for your purpose. Oh thank you. I liked this script because it is very fast but couldn't save the results to file, the way i wanted. I tried to use your script to ping an array of hosts from a file (without IPs) and couldn't find a way to do it. Maybe i missed something. Is there a way to do it? Link to comment Share on other sites More sharing options...
Gianni Posted April 24, 2018 Share Posted April 24, 2018 1 hour ago, pintas said: I tried to use your script to ping an array of hosts from a file (without IPs) and couldn't find a way to do it. Maybe i missed something. Is there a way to do it? ... not to hijack this thread, I place a simple example in the other thread... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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