Jump to content
Sign in to follow this  
stev379

Ping returns

Recommended Posts

stev379

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!

Share this post


Link to post
Share on other sites
flaxcrack

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()

Share this post


Link to post
Share on other sites
Icpic

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

Share this post


Link to post
Share on other sites
Wolfteeth

Hi, @ALL,

I have the same problem and still feel confused. why my Ping to a alive IP address always return Offline status?

Local $g_IP = "192.168.12.111"
Local $status = ping($g_IP)
MsgBox(0,$status, @error)

Share this post


Link to post
Share on other sites
Geir1983

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.