Jump to content

Ping returns


stev379
 Share

Recommended Posts

These are the Help File's listed returns for AutoIT's "Ping".

When the function fails (returns 0) @error contains extended information:
 1 = Host is offline
 2 = Host is unreachable
 3 = Bad destination
 4 = Other errors

Why does AutoIT's "Ping" return "1" when the host is actually online? All of the "1" returns I get return replies when I use Windows "Ping". I think it's just a grammatical thing I'm misunderstanding.

Also, I've gotten "6" as a return for a number of printers I've pinged. What does the "6" indicate?

$File = FileOpen(@scriptdir & "\PTR_Compared_DIFF_TEST.txt", 0)
$FileOut = FileOpen(@scriptdir & "\PTRsPinged.txt", 1)

If $File = -1 Then
    MsgBox(0, "Error", "Unable to open " & @ScriptDir & " PTR_Compared_DIFF.txt.")
    Exit
EndIf
If $FileOut = -1 Then
    MsgBox(0, "Error", "Unable to open  " & @ScriptDir & " PTRsPinged.txt.")
    Exit
EndIf

While 1
    $line = FileReadLine($File)
    If @error = -1 Then ExitLoop
        
        $Ping = Ping($line, 5000)
        If $Ping Then
        ;Msgbox(0,"Status","Online, roundtrip for " & $line & " was:" & $Ping)          
            FileWriteLine($FileOut, $line & "   " & $Ping)
        Else
        ;Msgbox(0,"Status","Pinging " & $line & " generated an error with number: " & @error)
            FileWriteLine($FileOut, $line & "   " & "Error= " & @error)
        EndIf
        
Wend

FileClose($file)
FileClose($FileOut)

Thanks for any help!

Link to comment
Share on other sites

These are the Help File's listed returns for AutoIT's "Ping".

When the function fails (returns 0) @error contains extended information:
 1 = Host is offline
 2 = Host is unreachable
 3 = Bad destination
 4 = Other errors

Why does AutoIT's "Ping" return "1" when the host is actually online? All of the "1" returns I get return replies when I use Windows "Ping". I think it's just a grammatical thing I'm misunderstanding.

Also, I've gotten "6" as a return for a number of printers I've pinged. What does the "6" indicate?

$File = FileOpen(@scriptdir & "\PTR_Compared_DIFF_TEST.txt", 0)
$FileOut = FileOpen(@scriptdir & "\PTRsPinged.txt", 1)

If $File = -1 Then
    MsgBox(0, "Error", "Unable to open " & @ScriptDir & " PTR_Compared_DIFF.txt.")
    Exit
EndIf
If $FileOut = -1 Then
    MsgBox(0, "Error", "Unable to open  " & @ScriptDir & " PTRsPinged.txt.")
    Exit
EndIf

While 1
    $line = FileReadLine($File)
    If @error = -1 Then ExitLoop
        
        $Ping = Ping($line, 5000)
        If $Ping Then
    ;Msgbox(0,"Status","Online, roundtrip for " & $line & " was:" & $Ping)          
            FileWriteLine($FileOut, $line & "   " & $Ping)
        Else
    ;Msgbox(0,"Status","Pinging " & $line & " generated an error with number: " & @error)
            FileWriteLine($FileOut, $line & "   " & "Error= " & @error)
        EndIf
        
Wend

FileClose($file)
FileClose($FileOut)

Thanks for any help!

Make sure the IP address you are trying to PING are up. Check out my code:

Ping(@IPAddress1, 5000)
If @error = 0 Then 
    MsgBox(0, "Host is up!", "Host is up!")
Else
    MsgBox(0, "ERROR!", "Error returns " & @error)
EndIf

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

Hi stev379,

I think the codes are for @error if you look at the example,

$var = Ping("www.AutoItScript.com",250)
If $var Then; also possible:  If @error = 0 Then ...
    Msgbox(0,"Status","Online, roundtrip was:" & $var)
Else
    Msgbox(0,"Status","An error occured with number: " & @error)
EndIf

for when the error occurs, the @error tells you what the error is,

Hope it helps

:lmao:

Edited by Icpic
Link to comment
Share on other sites

  • 8 years later...

Way to resurrect an old thread :P

Like it has been stated before in this thread you need to first check for @error, if no error then the return of the function is the time in ms for ping to return.

Local $g_IP = "192.168.12.111"
Local $status = ping($g_IP)
If @error Then
    Msgbox(0,"Status","Offline, error code: " & @error)    
Else
    Msgbox(0,"Status","Online, roundtrip was: " & $status & "ms")
EndIf
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...