Sign in to follow this  
Followers 0
Guest ghetek

reporting a ping from dos

18 posts in this topic

I want to report the errorlevel from a dos ping to autoit. is there a way to do that?

Share this post


Link to post
Share on other sites



I want to report the errorlevel from a dos ping to autoit.  is there a way to do that?

I've seen it scripted in the autoit forum with yahoo

do a

>ping.txt

to get the ping content then parse it

Rick


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here's an example of using the return of a DOS command. This method only works with RunWait (and not Run) but it will return the exit code of the program that was run. In the case of ping, a 0 means the host was up and 1 means it was down.

$result = RunWait(@ComSpec & " /c ping www.google.com", "", @SW_HIDE)
MsgBox(0, "Trial 1", "Result of google ping: " & $result)
$result = RunWait(@ComSpec & " /c ping www.goble-de-gook.com", "", @SW_HIDE)
MsgBox(0, "Trial 2", "Result of garbage ping: " & $result)

Edited to make more sense

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try the following code. It displays the errorlevel from ping command:

$sCmd = @ComSpec & " /c ping.exe"

; displays "0"
$sCmdParm = "www.yahoo.com"
$iRetCode = RunWait( $sCmd & " " & $sCmdParm)
MsgBox( 0, "Ping Return Code", $iRetCode )

; displays "1"
$sCmdParm = "test.yahoo.com"
$iRetCode = RunWait( $sCmd & " " & $sCmdParm)
MsgBox( 0, "Ping Return Code", $iRetCode )
Edited by midiaxe

Share this post


Link to post
Share on other sites

aaaaaaaaaaaaaah :huh2:

:postal:

I need help, this is driving me crazy :D

When i ping a "unknown host" your script works fine (it send back result 1), but if i ping a server that is not responding, it still give me a 0 as its working.

Would it be possible to:

Ping a server:

Result = 1 (unknow host) write to ini "fail"

Look for the word "Request timed out" and write to ini "fail"

Result = 0 (Reply) write to ini "Succed"

argh, why is it giving me a 0 if there is no reply :)


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

...

When i ping a "unknown host" your script works fine (it send back result 1), but if i ping a server that is not responding, it still give me a 0 as its working.

...

argh, why is it giving me a 0 if there is no reply  :D

Because the server was reached and the ping did it's job successful.

When the server is not answering to the ping, it's not the fault of ping.exe

I don't have a server here wich is configured not to answer to a ping, so that I could test it. But I think it must be some kind of that reason.

arctor

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I found this in the other thread:

var = FileRead ("mypath\my.txtr", FileGetSize ("mypath\my.txt ))

if stringinstr ($var,"mystring") then

msgbox(4096,"Hurray","Only one line of code and I don't have to read line by line")

endif

And think i will use that, if i can get the ping result into a txt file.

And one know how i can pipe the result?

ping.exe www.autoitscript.com > test.txt

Will that work?

yea, it works :D

Sorry for posting before testing, but i'm getting used to get errors all the time :huh2:

Edited by Doxie

Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

I found this in the other thread:

var = FileRead ("mypath\my.txtr", FileGetSize ("mypath\my.txt ))

if stringinstr ($var,"mystring") then

msgbox(4096,"Hurray","Only one line of code and I don't have to read line by line")

endif

And think i will use that, if i can get the ping result into a txt file.

And one know how i can pipe the result?

ping.exe www.autoitscript.com > test.txt

Will that work?

yea, it works :D

Sorry for posting before testing, but i'm getting used to get errors all the time :huh2:

hehe I just posted that

you may need http: but ya that's what I've seen people do

don't forget to clear the var when you're done

$var=""

Rick


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

Hurray!!!

Its all working :D

ping.exe -n 1 127.0.0.1 > test.txt ;This is making a reply

ping.exe -n 1 192.168.0.1 > test.txt ;This is not making a reply

$var = FileRead ("test.txt", FileGetSize ("test.txt" ))

if stringinstr ($var,"Reply") then

msgbox(4096,"Hurray","Reply")

Else

msgbox(4096,"Doh","No Reply")

endif

I need this line because i'm making a ADSL Status tool for my users.

And this "function" is need to test if they are logged in to their ISP.

If they can ping 10.0.0.6, they got contact with their ISP.

If they can ping www.microsoft.com, they are logged in.

If 10.0.0.6 succed, but microsoft fails, it will open their login page. :huh2:

It also check some other settings, and now it all works perfectly, this was the last problem i had.


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

don't forget to clear the var when you're done

$var=""

Rick

Everytime i run the ping it rewrite the txt file, so i get a fresh txt file each time.

What exactlly could happend if i dont clear the $var? :D


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

...

ping.exe www.autoitscript.com > test.txt

...

When you are already on the cmdline, why do not do the rest of it also there.

You don't need to redirect to a textfile, then load it with autoit and then find the right string in autoit.

Just use a one liner. Pipe the output to find. The /i makes it caseunsensitiv.

$res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"')
MsgBox(0, "Output", "PingResult: " & $res)

When string is found you will get errorlevel 0, if not, errorlevel 1.

You can also use a ping.exe -n 1 for just ping one time instead of three.

One Note: To get back the errorlevel from a commandline-prog as a result in AutoIt don't seems to work with Win98.

arctor

Edit: Forgot a space. -n 1

@Tutor2000: You don't need HTTP for a ping

Edited by Arctor

Share this post


Link to post
Share on other sites

Sweet dude...

One less file to think about :huh2:

Even tough this is taking a bit longer (if no reply) then it does with > .txt

Wonder why is that? :D

But i prefer your last suggestion, very nice and handy.

Thanks, ill mention your name in the "About" hehe


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

Sweet dude...

One less file to think about :huh2:

Even tough this is taking a bit longer (if no reply) then it does with > .txt

Wonder why is that?  :D

But i prefer your last suggestion, very nice and handy.

Thanks, ill mention your name in the "About"  hehe

for me it is better to find the string "TTL" , because ,for example, in Windows Xp Italian "Reply" is translated "risposta".

bye

Share this post


Link to post
Share on other sites

When you are already on the cmdline, why do not do the rest of it also there.

You don't need to redirect to a textfile, then load it with autoit and then find the right string in autoit.

Just use a one liner. Pipe the output to find. The /i makes it caseunsensitiv.

$res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"')
MsgBox(0, "Output", "PingResult: " & $res)

When string is found you will get errorlevel 0, if not, errorlevel 1.

You can also use a ping.exe -n 1 for just ping one time instead of three.

One Note: To get back the errorlevel from a commandline-prog as a result in AutoIt don't seems to work with Win98.

arctor

Edit: Forgot a space. -n 1

@Tutor2000: You don't need HTTP for a ping

I don't like find

I've found it worked differently with different OS's. Could be my inexptitude (and spelling ld)

Thanks for the http info

Rick


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

$res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"')

Why does not @SW_HIDE work with above code?


Were ever i lay my script is my home...

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

$res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"')

Why does not @SW_HIDE work with above code?

I had the same problem with the PowerArchiver commandline tool.

(Using your command as an example) I used this:

$res = RunWait(@ComSpec & ' /k ping www.yahoo.com | find /i "string_you_want_to_find && EXIT"', '', @SW_HIDE)
Edited by SlimShady

Share this post


Link to post
Share on other sites

Works for me, could it be you forgot the parameter for the startup Path before the @SW_HIDE ?

Try this one:

$res = RunWait(@ComSpec & ' /c ping www.yahoo.com | find /i "string_you_want_to_find"','',@SW_HIDE)
msgbox(0,'debug',$res)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks, is now working. :D


Were ever i lay my script is my home...

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  
Followers 0