FreeRider Posted October 22, 2007 Posted October 22, 2007 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 FreeRiderHonour & Fidelity
Bert Posted October 22, 2007 Posted October 22, 2007 Hard to say unless we can see your script. A guess is put the ping in a msgbox and see what you are getting from the ping. If it is just a 1, then that is the round trip time. The Vollatran project My blog: http://www.vollysinterestingshit.com/
FreeRider Posted October 24, 2007 Author Posted October 24, 2007 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 FreeRiderHonour & Fidelity
BrettF Posted October 24, 2007 Posted October 24, 2007 $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? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
weaponx Posted October 24, 2007 Posted October 24, 2007 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.
FreeRider Posted October 26, 2007 Author Posted October 26, 2007 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. FreeRiderHonour & Fidelity
weaponx Posted October 26, 2007 Posted October 26, 2007 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now