Message Boards Message Boards

0
|
7336 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to test for internet connectivity from within a calculation

Posted 10 years ago

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.

POSTED BY: David Reiss
4 Replies

Yes, when I do a ping in the terminal on OS X it runs without stopping until I do a control-c.

POSTED BY: David Reiss
Posted 10 years ago

"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.

POSTED BY: Bill Simpson

Hmmmm... if I turn off my WIFI I get:

In[3]:= Run["ping Google.com"]

Out[3]= 17408

But if I have it on, when I execute

Run["ping Google.com"]

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. ;-)

POSTED BY: David Reiss
Posted 10 years ago
Run["ping some.domain.name"]

seems to either return a 0 if it successfully gets a ping response or 1 if it fails.

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract