Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Connection Status using MATLAB

Tags:

matlab

Is there a way to check if I'm connected to the internet using MATLAB? Is there a function that returns true if it's connected to the internet?

like image 600
Mas ooD Avatar asked Oct 24 '13 04:10

Mas ooD


2 Answers

A similar approach to the above:

function tf = haveInet()
  tf = false;
  try
    address = java.net.InetAddress.getByName('www.google.de')
    tf = true;
  end
end

It does have the benefit of not spawning an additional process and being independent from the fact, whether a particular site may at the moment be unavailable (which might be a good or bad feature).

like image 126
sebastian Avatar answered Oct 04 '22 07:10

sebastian


How about using a ping to one of Google's DNSes?

if ispc
    C = evalc('!ping -n 1 8.8.8.8');    
elseif isunix
    C = evalc('!ping -c 1 8.8.8.8');        
end
loss = regexp(C, '([0-9]*)%.*loss', 'tokens');
connected = ~isempty(loss) && str2double(loss{1}{1})==0;
like image 43
Rody Oldenhuis Avatar answered Oct 04 '22 07:10

Rody Oldenhuis