Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Check internet connection status using Matlab
Date: Fri, 17 Oct 2008 19:52:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 33
Message-ID: <gdaqd3$lt0$1@fred.mathworks.com>
References: <cd7fd4a0-a476-4290-a70d-696a8800d7bf@v72g2000hsv.googlegroups.com> <c562fa59-86ba-4fc0-98d3-dad9b19b5051@a70g2000hsh.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224273123 22432 172.30.248.35 (17 Oct 2008 19:52:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 17 Oct 2008 19:52:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869596
Xref: news.mathworks.com comp.soft-sys.matlab:495891


Jaime Zamora <jaime.zamora@gmail.com> wrote in message <c562fa59-86ba-4fc0-98d3-dad9b19b5051@a70g2000hsh.googlegroups.com>...
> On Oct 17, 1:12=A0pm, "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

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