Sign in to follow this  
Followers 0
_Chris_

Ping command

10 posts in this topic

i am using the ping command which should ping until it gets a responce, if it does then it moves on the next bit, if it hasent got a reply after 20 seconds it should show the message box. It just comes up streight away! HELP!

Func Test()
    $pres= ping("192.168.1.1",20000)
Select
Case $pres= "0"
    MsgBox(0x40, "Conection Failed", "Your network Connection has failed, The program will now exit")   
EndSelect
EndFunc

Share this post


Link to post
Share on other sites



From the helpfile:

Failure: Returns 0 if host is not pingable or other network errors occurred and sets @error. (See Remarks)

Did you first check to see if the IP was good to test your script? You also may want to set a error statement. Something like this:

Func Test()
    $pres= ping("192.168.1.1",20000)
Select
Case $pres= "0"
    MsgBox(0x40, "Conection Failed", "Your network Connection has failed, The error code is" & @error)    
EndSelect
EndFunc

Share this post


Link to post
Share on other sites

Thanks for your help!

The ip is the router ip so its good! i can ping it from cmd prompt

I have the coding i need. That was just a sample. The problem i am having is that it dosent wait 20 seconds before it times out!

Share this post


Link to post
Share on other sites

Thanks for your help!

The ip is the router ip so its good! i can ping it from cmd prompt

I have the coding i need. That was just a sample. The problem i am having is that it dosent wait 20 seconds before it times out!

The timeout portion only happens if it's not returning a ping... if it's returning one, it's not going to wait for 20 seconds.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

yes i know thats the point! When my network conection is disconected (e.g. as part of the program i change ip address) during that time it should not be able to ping the address but should wait 20 seconds to give the program chance to renew the ip

Share this post


Link to post
Share on other sites

yes i know thats the point! When my network conection is disconected (e.g. as part of the program i change ip address) during that time it should not be able to ping the address but should wait 20 seconds to give the program chance to renew the ip

Nope, still not getting you... hold on <sips coffee> :P <hates coffee> :)

So your saying the address no longer exists... but ping is returning saying it does?

If the above is true, then how are you changing the address, and how are you confirming other than autoit (manually) that it doesn't exist while your doing whatever you doing?

If you need a specific timeout function for something other than what I'm not understanding... you may look at something like:

$iTimer = TimerInit()
While (Ping("192.168.1.1") Or (TimerDiff($iTimer) / 1000 <= 20))
    Sleep(10)
WEnd

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hes prolly disconnecting the internet connection, then reenableing it. Thus, renewing the ip.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

_RunDos('netsh interface ip set address name="Wireless Network Connection" source=static addr=192.168.1.10 mask=255.255.255.0')
_RunDos('netsh interface ip set address name="Wireless Network Connection" gateway=192.168.1.1 gwmetric=0')
_RunDos('netsh interface ip set dns name="Wireless Network Connection" source=static addr=194.74.65.68')
_RunDos('netsh interface ip add dns name = "Wireless Network Connection" addr = 194.74.65.69')

I use that to change the ip address of the computer. I then want to test the connection to make sure it is connected. I want it to ping the router to make sure their is a connection, but if it dosent get a reply after 20 seconds i want it to give up and close the program.

Share this post


Link to post
Share on other sites

RIGHT...

Ive made a few developments, i need to look at the error code, the error code must be 2 (host unreachable) for it to close the program. I still REALLY need a way of running a ping for 20 seconds. May be i could run a small ping (e.g. with a 250 milisecond time out) but run it 50 times, thus giving the system time to get its new address. I would also like to put in a cancel button to stop it pinging

Share this post


Link to post
Share on other sites

Just use a while loop like i did above and change the Ping out.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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