Jump to content
Sign in to follow this  
FreeRider

Ping Error 1

Recommended Posts

Hi all,

I have a little problem with the ping command in a script. I have @error set to 1 despite

the host is online. The command line is very simple like $ret=Ping(IPadress).

When I try to manually ping the server using a DOS commande line it works...

remark : When I run the script on a LAN, or ADSL connection it works, @error is set to 1 only when using a dialup connection with a GPRS card (3G).

Any Idea to bypass of fix it ?

Thanks for you help

Share this post


Link to post
Share on other sites

Hello Volly,

I confirm I retreive the Error Code and not the roundtrip time... But I found a bypass to the problem.

The script I use returns the Error 1 (Host Offline) only form some of the locations where users are.

I assume the network configuration on these location is restricted which could drives the Ping command to

return this error code.

I choosed to use the native Ping.exe to perform the action and I get the result back using the "$STDOUT_CHILD" constant.

Here is the script with the

;==============================================

; STDIO Constants

;==============================================

Global Const $STDIN_CHILD = 1

Global Const $STDOUT_CHILD = 2

Global Const $STDERR_CHILD = 4

;==============================================

Dim $PUBLICConnected

;**********************************************************************

;************ This was the first way I used to perform the ping *************

;**********************************************************************

;$PUBLICConnected=Ping("www.google.com") ==>

;**********************************************************************

;************ This is the way I found to bypass the "radom" Error 1 *************

;**********************************************************************

$Foo=Run(@ComSpec & " /c ping.exe www.google.com", @SystemDir, @SW_HIDE,$STDOUT_CHILD)

While 1

$StdOutLine = StdoutRead($Foo)

If @error Then ExitLoop

If StringInStr($StdOutLine,"Ping Request could not find") > 0 Then ContinueLoop

$PUBLICConnected="YES"

ExitLoop

WEnd

If Not $PUBLICConnected Then

$Msg="Server's not responding"

MsgBox(0,"Pinging test",$Msg & @CRLF & "Result : " & @error)

Exit

Else

$Msg="Server's responding..."

MsgBox(0,"Pinging test",$Msg & @CRLF & "Resultat : " & $PUBLICConnected)

Exit

EndIf

Share this post


Link to post
Share on other sites

$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

What does that return?

Share this post


Link to post
Share on other sites

I see a big problem here Chris.

You are making the assumption that Dim $PUBLICConnected is being set to zero. Then instead of using the builtin true / false you set $PUBLICConnected="YES".

Very bad. Because then you have this condition "If Not $PUBLICConnected Then" which again would assume $PUBLICConnected could ever have been zero.

So basically you are using a boolean comparison against a string so it is very likely that a ping could fail, and still return successful with your code.

Share this post


Link to post
Share on other sites

Hi 'weaponx'

I also tried replacing "If not $PUBLICConnected" by "if $PUBLICConnected <> "YES" and I obtained the same return code.

I think the problem comes from the network configuration of some of the locations, where they are may be network restrictions which

drives Autoit to retreive a wrong return code.

As it always work when pinging manually (DOS command line) I used this way to bypass the problem and now it works whatever the location...

Many thanks for your help.

Share this post


Link to post
Share on other sites

Just keep the code clean and simple:

;METHOD 1
$PUBLICConnected = Ping("www.google.com")

If NOT $PUBLICConnected Then
    Switch @error
        Case 1
            MsgBox(0,"","Host is offline")
        Case 2
            MsgBox(0,"","Host is unreachable")
        Case 3
            MsgBox(0,"","Bad destination")
        Case 4
            MsgBox(0,"","Other errors")
    EndSwitch

Else
    MsgBox(0,"","Ping result: " & $PUBLICConnected & " ms")
EndIf

;METHOD 2
;This will return ping exitcode. 0 = success 1 = fail (note this is backwards from autoit return codes)
$result = RunWait("ping.exe www.google.com")
If $result Then
    MsgBox(0,"","Ping failed")
Else
    MsgBox(0,"","Ping successful")
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  

×
×
  • Create New...