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?
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).
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With