Jump to content

Ping Function always return 4.


GraaF
 Share

Recommended Posts

I've been playing around with the ping function, and according to the help page, the ping function should be able to return 4 types of errors.

But no matter what i do, no matter what i enter into the ping field, it returns error 4 for some reason? I tried with countless stuff, am i misusing the function?

Quote
Success: the roundtrip-time in milliseconds ( greater than 0 ).
Failure: 0 if host is not pingable or other network errors occurred and sets the @error flag to non-zero.
@error: 1 = Host is offline
2 = Host is unreachable
3 = Bad destination
4 = Other errors
GUICtrlSetData($probar, "Testing connection..")
            $inettest1 = ping("www.Imnotawebsite.nope", 250)
            If $inettest1 Then
            GUICtrlSetData($probar, "Connection was made after: " & $inettest1 & "MS")
         Else
            If @error = 1 Then
            GUICtrlSetData($probar, "An unknown error occurred code: " & @error)
         Else
            If @error = 2 Then
            GUICtrlSetData($probar, "An unknown error occurred code: " & @error)
         Else
            If @error = 3 Then
            GUICtrlSetData($probar, "An unknown error occurred code: " & @error)
         Else
            If @error = 4 Then
            GUICtrlSetData($probar, "An unknown error occurred code: " & @error)
         EndIf
         EndIf
         EndIf
         EndIf
         EndIf

 

Link to comment
Share on other sites

Just now, JohnOne said:

Even an actual real domain?

I mean i can ping google.com and the script run fine, but incase i ping a domain thats offline it will return the error 4 instead of error 1?..

The function works fine, but i don't like that no matter what goes wrong in the function it will return the error code 4, while error code 1 might have been the problem.

 

Let me explain:

If i ping www.google.com no problem, no errors everything is perfect.

Now lets say i ping a domain which is offline the script SHOULD return error code 1 or 2, yet i get error code 4.

 

Link to comment
Share on other sites

Have you tried it on a real domain that is off-line rather than a made up domain that does not exist. I correctly get @error = 2 for domains at work that I know exist but are unreachable from my home PC.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Just now, Bowmore said:

Have you tried it on a real domain that is off-line rather than a made up domain that does not exist. I correctly get @error = 2 for domains at work that I know exist but are unreachable from my home PC.

Yeah i tried with websites that are unreachable from here, still error 4.

Link to comment
Share on other sites

  • Developers
49 minutes ago, GraaF said:

Yeah i tried with websites that are unreachable from here, still error 4.

What about supplying some exact information so we can actually check it? ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 hour ago, JohnOne said:

Have you tried changing An unknown error occurred code to the real corresponding error?

It prompt

"An unknown error occurred" & @error

@Error part shows the real error..

 

 

1 hour ago, Jos said:

What about supplying some exact information so we can actually check it? ;)

Jos

What information would you like? I included the script & as i said before i tried with multiply real and fake websites it either run right through no errors or return error 4.

 

Link to comment
Share on other sites

  • Developers

Show us a script that can be ran with the hostnames you are testing with would help for starters. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 hour ago, GraaF said:

i tried with multiply real and fake websites it either run right through no errors or return error 4.

What's ping from windows returningm using a fakewebsite? i get:

Quote

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\Bert>ping www.autoitscript2.com

Ping-Anforderung konnte Host "www.autoitscript2.com" nicht finden. Überprüfen Sie den Namen, und versuchen Sie es erneut.

C:\Users\Bert>

= "Host not reachable. Check name and try again"

Link to comment
Share on other sites

GraaF,

This works for me...

#include <array.au3>

Local $aURLS = [ _
        'www.google.com', _
        'www.autoitscript.com', _
        'www.probablynotawebsite.com', _
        'www.samolyk.net' _
        ]

Local $ret

For $i = 0 To UBound($aURLS) - 1

    $ret = Ping($aURLS[$i], 250)
    If $ret = 0 Then
        Switch @error
            Case 1
                ConsoleWrite('! ret = 1...' & $aURLS[$i] & ' is offline' & @CRLF)
            Case 2
                ConsoleWrite('! ret = 2...' & $aURLS[$i] & ' is unreachable' & @CRLF)
            Case 3
                ConsoleWrite('! ret = 3...' & $aURLS[$i] & ' is a bad destination' & @CRLF)
            Case 4
                ConsoleWrite('! ret = 4...' & $aURLS[$i] & ' other error' & @CRLF)
        EndSwitch
        ContinueLoop
    EndIf

    ConsoleWrite('+ ' & $aURLS[$i] & ' reached in ' & $ret & ' milliseconds' & @CRLF)

Next

note - the timeout is so short (250 ms) that sometimes valid websites are reported as unreachable

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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