Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Check internet connection status using Matlab

359 views
Skip to first unread message

Jaime Zamora

unread,
Oct 17, 2008, 12:04:44 PM10/17/08
to
Hi All, is there a way to check if I'm connected to the internet using
matlab?

Best,
Jaime

Matt Fig

unread,
Oct 17, 2008, 12:12:01 PM10/17/08
to
doc web

Jaime Zamora

unread,
Oct 17, 2008, 12:15:17 PM10/17/08
to
On Oct 17, 1:12 pm, "Matt Fig" <spama...@yahoo.com> wrote:
> doc web

I would like to write a function that returns true if it's connected
to the internet.

Best,
Jaime

Walter Roberson

unread,
Oct 17, 2008, 12:53:59 PM10/17/08
to
Jaime Zamora wrote:
> is there a way to check if I'm connected to the internet using
> matlab?

Only if you add additional hardware to be able to verify a quantum-cryptography
secured connection with a site you have *personally* installed the quantum
cryptography hardware on.

If you do anything less than quantum cryptography, then you will be unable
to tell the difference between *really* being connected to the internet
versus being connected to a private network that is lying and -telling- you
are connected. Oh, sure you can have root certificates and "web of trust"
PGP signed keys, but any of those can be broken with enough time and money
(or bribery or covert operations to steal the keys).


Checking to see whether you are "connected to the internet" is, in practice,
a singularly useless thing to do. Suppose you -are- connected to the "internet"
and the check gives you an honest "Yes" answer. Now what??

Being "connected to
the internet" tells you absolutely nothing about whether you will be able to reach
any particular service at any particular site. The site might be crashed; the site
might be down for routine maintenance; there might be widespread power outages
that took down the network somewhere between you and the site; a back-hole might
have torn up the wires or fibers; a mouse or rabbit or ground-hog might have chewed
apart an important connection on the way; there might be a bug in the network
routing tables; someone might have deliberately "poisoned" the network routing tables;
there might be a denial-of-service attack that is preventing you from reaching the
places you want to go; there might be a bug in someone's firewall rules along the way;
someone's firewall might be deliberately blocking you because you are not authorized
to access the service; someone's firewall might be blocking you because you don't
happen to know the right security codes to get through; your ISP might be blocking you
because the government or a court order requires them to do so (think China, or think
access to Nazi information from inside Germany to outside); your ISP might be
blocking you because you have exceeded your account limits; your ISP might be blocking
you because it is a meddling corporate entity concerned with profits and not with people.
And so on.

Scott Burnside

unread,
Oct 17, 2008, 3:52:03 PM10/17/08
to
Jaime Zamora <jaime....@gmail.com> wrote in message <c562fa59-86ba-4fc0...@a70g2000hsh.googlegroups.com>...

Crude, but it works:

function flag = isnet()
% This function returns a 1 if basic internet connectivity
% is present and returns a zero if no internet connectivity
% is detected.

% define the URL for US Naval Observatory Time page
url =java.net.URL('http://tycho.usno.navy.mil/cgi-bin/timer.pl');

% read the URL
link = openStream(url);
parse = java.io.InputStreamReader(link);
snip = java.io.BufferedReader(parse);
if ~isempty(snip)
flag = 1;
else
flag = 0
end
return

hth,
Scott

Walter Roberson

unread,
Oct 17, 2008, 4:13:16 PM10/17/08
to
Scott Burnside wrote:
> Jaime Zamora <jaime....@gmail.com> wrote in message <c562fa59-86ba-4fc0...@a70g2000hsh.googlegroups.com>...
>> On Oct 17, 1:12=A0pm, "Matt Fig" <spama...@yahoo.com> wrote:

>> I would like to write a function that returns true if it's connected
>> to the internet.

> Crude, but it works:

> % This function returns a 1 if basic internet connectivity
> % is present and returns a zero if no internet connectivity
> % is detected.

> % define the URL for US Naval Observatory Time page
> url =java.net.URL('http://tycho.usno.navy.mil/cgi-bin/timer.pl');

And if I am the DNS administrator for your network, and I define
tycho.usno.navy.mil to resolve to one of the local machines, then
although you might detect that a connection was made, it would
not be an *internet* connection that had been detected.


You also didn't meet the specifications. The specification was not
whether "internet connectivity is detected", the specification
was whether it is "connected to the internet". For example if I were
the firewall administrator for your network and I had blocked all outgoing
http except to certain specific sites (e.g., allowed access to headquarter's
press releases but other sites permitted only upon -proof- that access
was required for your work), then because you would be "connected to
the internet", the function would be required to return true, even though
the function cannot contact USNO.


Sites *do* get blocked. Blocking many sites is a corporate legal requirement for
many companies -- for example, in many companies, blocking access to any
kind of nudity or sexuality is required, with the requirement sometimes imposed
by law (e.g., many US libraries are -required- to prevent minors from accessing
adult sites.) And then there are the legal requirements under
Sarbanes-Oxley, which can require companies to block access to competitors
as elements of proof that they are not in collusion with the competitors...

Scott Burnside

unread,
Oct 17, 2008, 4:21:02 PM10/17/08
to
Walter Roberson <robe...@hushmail.com> wrote in message <kl6Kk.1126$YN3...@newsfe12.iad>...

Understood Walter. All your caveats are valid.

Scott

Scott Burnside

unread,
Oct 17, 2008, 7:21:01 PM10/17/08
to
"Scott Burnside" <n...@spam.com> wrote in message <gdaqd3$lt0$1...@fred.mathworks.com>...

Hmmm. Needs a try/catch:

function flag = isnet()
% This function returns a 1 if basic internet connectivity
% is present and returns a zero if no internet connectivity
% is detected.

% define the URL for US Naval Observatory Time page
url =java.net.URL('http://tycho.usno.navy.mil/cgi-bin/timer.pl');

% read the URL
try


link = openStream(url);
parse = java.io.InputStreamReader(link);
snip = java.io.BufferedReader(parse);

catch
flag = 0;
return
end


if ~isempty(snip)
flag = 1;
else
flag = 0;
end
return

% end of code

Scott

Jan Simon

unread,
Oct 18, 2008, 9:48:01 AM10/18/08
to
Dear Walter Roberson!

> Checking to see whether you are "connected to the
> internet" is, in practice, a singularly useless
> thing to do.

Perhaps it is enough for Jaime Zamora to check, if he is not disconnected. E.g. for a task like "start the mail program only, if it looks, like the machine has contact".

Of course, a super-user can pretend an internet connection ever. We are all aware, that the impression of reading the Matlab Newsreader pages could be the result of a smartish virus working on out local host feeding the browser with faked messages. My complete mail correspondence of the last year could be a virtual product of tricky malware.

Nevertheless, why stopping at this trivial point? Sensory perception of even humans could be remote controlled at all.

Plato's parable of the cave had less special effect than The Matrix. However, both describe the problems of intelligent life forms and Matlab: There is no way to answer the question, if any input is "real". There are no red and blue pills.

How to proceed with programing/living than?
In my personal opinion, Jaime Zamora can ask his imperfect question (is the machine connected?) and "believe" the found answer with respect to the potential limits. So if his internet connection is a good fake, it is as good as a "real" connection!

Kind regards, Jan

Walter Roberson

unread,
Oct 18, 2008, 11:03:18 PM10/18/08
to
Jan Simon wrote:
> Dear Walter Roberson!

>> Checking to see whether you are "connected to the
>> internet" is, in practice, a singularly useless
>> thing to do.

> Perhaps it is enough for Jaime Zamora to check, if he is not disconnected. E.g. for
> a task like "start the mail program only, if it looks, like the machine has contact".

In Canada and the USA, it is standard practice for residential ISPs to block
outgoing access to all mail servers except the ISP's own mail server. This blocks
PCs infected with viruses or trojan horses from being able to run mass spam
or virus-sending attacks on systems in the rest of the world. You might be
"connected to the internet" and yet not be able to reach your mail server
of choice (and most of the ISPs did not bother to notify customers before
they started doing this kind of blocking.)

As I said before, checking whether you are "connected to the internet" is,
in practice, a singularly useless thing to do. If you have a specific
activity you want to undertake, then check to see whether you can do *that*,
not whether you are "connected to the internet". If you want to know
whether your PPPoE client is loaded and talking to your ADSL modem,
then check -that-.

Jan Simon

unread,
Oct 19, 2008, 6:52:01 AM10/19/08
to
Dear Walter Roberson!

> If you have a specific activity you want to undertake, then
> check to see whether you can do *that*,
> not whether you are "connected to the internet". If you
> want to know whether your PPPoE client is loaded and
> talking to your ADSL modem, then check -that-.

Exactly.

The question was (analogous): **How** do I check the availability of a certain internet service in Matlab?
We cannot clear the question **what** Jaime Zamora wants to do.

Quantum-cryptography would not help for this reason, usually.

Considering evil DNS administrators would not help, either.

Theories about human perception would not help, either (I have to admit).

"java.net.URL" recommended by Scott can help (but not under 100% of all imaginable and not-imaginable situations).

"URLREAD" might help also (but not under 100%...).

Good luck, Jan

Scott Burnside

unread,
Oct 19, 2008, 3:09:02 PM10/19/08
to
"Jan Simon" <matlab.T...@nMINUSsimon.de> wrote in message <gdf3gh$m5u$1...@fred.mathworks.com>...

I agree with Walter in that I think a purpose-built remote entity who responded to strongly encrypted interrogations with strongly encrypted replies would be as close as you could get but certainly not 100%.

Scott

Walter Roberson

unread,
Oct 19, 2008, 6:55:02 PM10/19/08
to
Scott Burnside wrote:

> I agree with Walter in that I think a purpose-built remote entity who responded to strongly
> encrypted interrogations with strongly encrypted replies would be as close as you
> could get but certainly not 100%.

That's why I mentioned quantum cryptography. With regular cryptography, you could have
a "man in the middle", if the "man in the middle" could solve the cryptographic
challenges sufficiently quickly -- something which cannot be done on any publicly
known system, but which is theoretically vulnerable to "quantum computing"
(all solutions theoretically calculated simultaneously), and which might plausibly
be within reach with publicly known technology based upon "biological computing"
(extreme mass parallelism at low price and low heat.) Is there any NSA, or
Mossad, or Men in Black covert system that can handle sufficiently strong
"man in the middle" challenges in real time? The answer to that is either "NO"
or "Walter Roberson is not authorized to even hear rumours of such a system
really existing", but "Absence of evidence is not evidence of absence".

But with quantum cryptography, "man in the middle" attacks are not *possible*
according to all current quantum physics: all experimentation so far indicates
that any attempt to "snoop" on quantum-entangled particle pairs would de-tangle
the particles, with the effect of randomizing the content of the transmitted
message. No possible "man in the middle" attack, because what is transferred
in quantum cryptography is not mere "information" that could be replicated.

Matthew Simoneau

unread,
Oct 20, 2008, 2:43:02 PM10/20/08
to
Scott, I think we can simplify your code by using URLREAD:


function flag = isnet()
% This function returns a 1 if basic internet connectivity
% is present and returns a zero if no internet connectivity
% is detected.

% define the URL for US Naval Observatory Time page

url = 'http://tycho.usno.navy.mil/cgi-bin/timer.pl';

% Try to connect to it.
[unused,flag] = urlread(url);

Scott Burnside

unread,
Oct 20, 2008, 5:56:03 PM10/20/08
to
"Matthew Simoneau" <mat...@mathworks.com> wrote in message <gdijfm$jk9$1...@fred.mathworks.com>...

Nice. Man that is compact.

Scott

Jason

unread,
Feb 6, 2010, 5:10:22 PM2/6/10
to
"Scott Burnside" <n...@spam.com> wrote in message <gdiupj$l2q$1...@fred.mathworks.com>...


similar response:

urlread('http://www.google.com')
??? Error using ==> urlread at 108
Error downloading URL.

if you use urlread and do a try catch type command you will get your function.

this returns html if it gets the site. the above error is if i turn my wireless connection off.

Kyle

unread,
Aug 16, 2010, 8:41:25 PM8/16/10
to
Jason,
a helpful tip:
When calling a function with output dependent on nargout:
ex.) minimum = min(x) vs. [minimum,index] = min(x),
you can use
[~,index] = min(x).
to ignore the first output arg, while the function sees nargin==2.
it speeds things up a little.
I also helps clear up clutter

Richard Crozier

unread,
Dec 16, 2010, 6:37:05 AM12/16/10
to
"Kyle " <kyle....@gmail.com> wrote in message <i4clrl$1ip$1...@fred.mathworks.com>...

Amazing what you learn while reading the newreader, now I know how to check the internet connection, and this amazing tip I'd never heard of before! I've often wished I could ignore some unnecessary arguments but thought it was impossible.

Geant Bepi

unread,
Dec 16, 2010, 7:35:21 AM12/16/10
to
"Richard Crozier" <r.cr...@ed.ac.uk> wrote in message <iectl1$crh$1...@fred.mathworks.com>...

>>>
It was edifying to read all your responses..It is amazing what you can do with Matlab :)

I invite the brains here to look at my simple problem mentioned below and help me with some tips;
link: http://www.mathworks.com/matlabcentral/newsreader/view_thread/297252#804997

thanks heaps!

0 new messages