Jump to content

Wait until I can ping 3 devices before I move on in the script


Go to solution Solved by sahsanu,

Recommended Posts

Im having my script restart 3 computers on my network and I want to have the script wait until they are all pingable before I move on with my script

Global $Number = 3 Global $IPAddress1 = "192.168.1.37" Global $IPAddress2 = "192.168.1.40" Global $IPAddress3 = "192.168.1.41" Global $IPArray[3] = [$IPAddress1, $IPAddress2, $IPAddress3];,"192.168.1.42"] Func Ping() For $p = 1 to $Number $PingTemp = Ping($IPArray[$p],250) Do Sleep(500) Until $PingTemp = 1 Next EndFunc

Global $Number = 3
Global $IPAddress1 = "192.168.1.37"
Global $IPAddress2 = "192.168.1.40"
Global $IPAddress3 = "192.168.1.41"
Global $IPArray[3] = [$IPAddress1, $IPAddress2, $IPAddress3];,"192.168.1.42"]

Func Ping()
For $p = 1 to $Number
   $PingTemp = Ping($IPArray[$p],250)        
        Do
            Sleep(500)
        Until $PingTemp = 1
    Next
EndFunc

This just hangs there. I can ping all the ip addresses from another machine.

*Edit - I was assuming that ping returned a true or false. Apparently it returns the ping time in milliseconds. I'm trying the following but getting bad results:

Global $Number = 3
Global $IPAddress1 = "192.168.1.37"
Global $IPAddress2 = "192.168.1.40"
Global $IPAddress3 = "192.168.1.41"
Global $IPArray[3] = [$IPAddress1, $IPAddress2, $IPAddress3];,"192.168.1.42"]

Func Ping()
For $p = 1 to $Number
     Do
        $PingTemp = Ping($IPArray[$p],250)       
        Sleep(500)
     Until Not @error
    Next
EndFunc
Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Global $IPArray[3] = ["192.168.1.1", "192.168.1.10", "192.168.1.11"]

_WaitHostsReady()

Func _WaitHostsReady()
    $iReady = 0
    
    While NOT $iReady
        $iOK = 0
        For $i = 0 To UBound($IPArray) - 1
            If Ping($IPArray[$i],250) Then $iOK += 1
        Next
        If $iOK = UBound($IPArray) Then $iReady = 1
        Sleep(500)
    WEnd
EndFunc

Is it OK with this code ?

Edited by jguinch
Link to comment
Share on other sites

Global $IPArray[3] = ["192.168.1.1", "192.168.1.10", "192.168.1.11"]

_WaitHostsReady()

Func _WaitHostsReady()
    $iReady = 0
    
    While NOT $iReady
        $iOK = 0
        For $i = 0 To UBound($IPArray) - 1
            If Ping($IPArray[$i],250) Then $iOK += 1
        Next
        If $iOK = UBound($IPArray) Then $iReady = 1
        Sleep(500)
    WEnd
EndFunc

??

Does the ?? mean its a guess? I had the For $p = 1 set wrong. I set it to $p = 0 but it wouldnt make a difference. My script wont move on after this.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

 Tried this with no luck

Global $Number = 3 
Global $IPAddress1 = "192.168.1.37" 
Global $IPAddress2 = "192.168.1.40" 
Global $IPAddress3 = "192.168.1.41" 
Global $IPArray[3] = [$IPAddress1, $IPAddress2, $IPAddress3];,"192.168.1.42"] 

Ping123()

Func Ping123() 

For $p = 1 to $Number      
     Do         
          $PingTemp = Ping($IPArray[$p],250)               
          Sleep(500)      
     Until $PingTime > 0     
Next EndFunc

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • Solution

Try this code:

Global $IPAddress1 = "192.168.1.37"
Global $IPAddress2 = "192.168.1.40"
Global $IPAddress3 = "192.168.1.41"
Global $IPArray[3] = [$IPAddress1, $IPAddress2, $IPAddress3]

_Ping() ;If you want lo limit the tries to ping all the machines simply add the number of tries _Ping(20) for example, by default are 10
If @error Then
    ConsoleWrite("One or more machines are down." & @CRLF)
Else
    ConsoleWrite("All machines are up and running." & @CRLF)
EndIf

Func _Ping($iMaxtries = 10)
    $iCountTotal = 0
    Do
        $iCount = 0
        For $p = 0 To UBound($IPArray) - 1
            $PingTemp = Ping($IPArray[$p], 250)
            If Not @error Then $iCount += 1
            Sleep(100)
        Next
        $iCountTotal += 1
        If $iCountTotal = $iMaxtries And $iCount < 3 Then
            Return SetError(1, 1, 1)
        EndIf
        Sleep(500)
    Until $iCount = 3
    Return 0
EndFunc   ;==>_Ping

Cheers,

sahsanu

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...