Page 1 of 1
Using Ping command
Posted: Wed May 30, 2012 8:40 pm
by derr1ck
Hi,
I need to be able to ping a domain form within my desktop program, I have tried using :-
put shell ("ping mydomain.com") into field 1
Put this doesn't work and it seems to lockup livecode and I need to force quit the program on my Mac.
Any ideas on how I can do this, would like to check if a website running or not and have a colour bar represent its state.
Re: Using Ping command
Posted: Wed May 30, 2012 8:58 pm
by Klaus
Hi Derrick,
one thing to know: SHELL calls in LiveCode are BLOCKING!
Means Livecode will wait until the shell command has finished,
which of course looks as if the app has crashed!
Sorry, no idea how to do this non-blocking.
Best
Klaus
Re: Using Ping command
Posted: Wed May 30, 2012 9:02 pm
by sturgis
If you're on windows it should return after 4 pings. If you're on ox x I believe ping continues indefinitely. To fix this use the -c switch
put shell("ping -c4 yourdomain.to.check.com") into field 1 -- will send 4 pings -c = count
Re: Using Ping command
Posted: Wed May 30, 2012 11:22 pm
by derr1ck
sturgis wrote:If you're on windows it should return after 4 pings. If you're on ox x I believe ping continues indefinitely. To fix this use the -c switch
put shell("ping -c4 yourdomain.to.check.com") into field 1 -- will send 4 pings -c = count
Thanks that seems to have worked

Re: Using Ping command
Posted: Fri Jun 01, 2012 8:54 am
by derr1ck
One other question:
How can I have the script repeat the ping command, say every 5 mins?
so far, via a button I check it by doing:-
set the backgroundColor of graphic monitor to "white"
put shell ("ping -c2 mydomain.com") into results
put item 2 of results into testit
if testit is empty then
set the backgroundColor of graphic monitor to "red"
else set the backgroundColor of graphic monitor to "green"
Re: Using Ping command
Posted: Fri Jun 01, 2012 9:33 am
by shaosean
If you take your code out of the mouseUp handler and create a new one, you can just use the
send command to call the handler every five minutes
Code: Select all
on mouseUp
doMyPing
end mouseUp
command doMyPing
set the backgroundColor of graphic monitor to "white"
put shell ("ping -c2 mydomain.com") into results
put item 2 of results into testit
if testit is empty then
set the backgroundColor of graphic monitor to "red"
else set the backgroundColor of graphic monitor to "green"
-- you will need a check here to see if you need to send the command or not
send "doMyPing" to me in 300 seconds
end doMyPing
Re: Using Ping command
Posted: Fri Jun 01, 2012 3:11 pm
by townsend
Any ideas on how I can do this, would like to check if a website running or not and have a colour bar represent its state.
Ping actually returns a trace route. If you just want to check if the website is up and running maybe you could just try grabbing a page.
Code: Select all
put URL("http://www.somewebsite.com/") into a.variable
Re: Using Ping command
Posted: Fri Jun 01, 2012 3:15 pm
by sturgis
This is a good point. Pinging the machine shows that its there and alive, but that doesn't necessarily mean apache (or whatever webserver they're using) is actually up and working. Hitting a page is probably the better option.
townsend wrote:Any ideas on how I can do this, would like to check if a website running or not and have a colour bar represent its state.
Ping actually returns a trace route. If you just want to check if the website is up and running maybe you could just try grabbing a page.
Code: Select all
put URL("http://www.somewebsite.com/") into a.variable
Re: Using Ping command
Posted: Fri Jun 01, 2012 11:42 pm
by shaosean
Of course some people do run servers that are not web servers, so just knowing that you can reach the darn thing is always good too

Re: Using Ping command, time response
Posted: Wed Dec 05, 2012 8:33 am
by ninetrees
Any ideas on how I can do this, would like to check if a website running or not and have a colour bar represent its state.
I modified the code of "shaosean" (Thanks!) to report the
average time for the ping command to a particular site. (apple.com gives the lowest ping time I've ever found.)
Code: Select all
command pingaSite
put shell ("ping -c4 -q -t4 www.apple.com") into results -- 4 pings, quiet (minimal) response, timeout 4 sec
put item 2 of results into s
if s is empty then
report "no response"
else -- parse the line: round-trip min/avg/max/stddev = 21.527/25.327/35.363/5.805 ms (item 2 of word 4)
put word 4 of the last line of results into s
set the itemdelimiter to "/"
put "Ave Ping: " && round(item 2 of s,1) && "ms" into field "pingTime" -- n/n/n/n ms
end if
end pingaSite