Using Ping command
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Using Ping command
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.
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
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
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
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
put shell("ping -c4 yourdomain.to.check.com") into field 1 -- will send 4 pings -c = count
Re: Using Ping command
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
![Smile :)](./images/smilies/icon_smile.gif)
Re: Using Ping command
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"
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
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
-
- Livecode Opensource Backer
- Posts: 430
- Joined: Sun Feb 13, 2011 8:43 pm
- Location: Seattle, USA
Re: Using Ping command
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.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.
Code: Select all
put URL("http://www.somewebsite.com/") into a.variable
Re: Using Ping command
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: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.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.
Code: Select all
put URL("http://www.somewebsite.com/") into a.variable
Re: Using Ping command
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 ![Wink ;-)](./images/smilies/icon_wink.gif)
![Wink ;-)](./images/smilies/icon_wink.gif)
Re: Using Ping command, time response
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.)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.
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