Is there a way to test whether (for desktop Mathematica) in the middle of a calculation whether there is internet connectivity?
The reason is that, if there is no internet connectivity (e.g., WIFI is turned off for the computer) then for my particular application will make use of cached material, but if there is connectivity then I will access the Wolfram knowledge-base.
There is the parameter $AllowInternet which determines whether accessing the internet is permitted, but this is different from determining if the internet is there to use.
Yes, when I do a ping in the terminal on OS X it runs without stopping until I do a control-c.
"My ping", well I think it is Microsoft's Win7 64 ping and I don't think I have messed with it, throws four pings and then exits with a status code.
I did carefully repeatedly test the code before posting it, both with hosts that would respond and hosts that would not.
Under FreeBSD and OpenBSD "ping -c 4 some.domain.name" will terminate after four pings. And I just tested that.
It looks like it might be the same on Linux, but there are so many variations that I'm never certain and I cannot reach a host to test that.
It looks like it might be the same on a Mac, but I cannot reach a host to test that.
Microsoft appears to use -n instead of -c if you want to change the default number of pings to throw. It will throw a bad option error message and list of options if you try using -c.
Apparently yours never terminates. I suppose you could verify this by opening a command line window and trying it there to see what it does.
Hmmmm... if I turn off my WIFI I get:
In:= Run["ping Google.com"]
But if I have it on, when I execute
it does not terminate and locks up the Kernel. Usually when one does a ping in a terminal it is a process that continues until one executes a control-c. I had to Kill my Mathematica to continue... the usual attempt to abort does not work in this case. So perhaps this is not quite a usable. ;-)
seems to either return a 0 if it successfully gets a ping response or 1 if it fails.