mundodelphi

programacion en delphi

Detectar si hay conexión a internet

detectar si hay conexión a internet con delphi, si queremos saber si la computadora tiene conexión a internet podemos usar el siguiente truco, con la función  Net_IsConnected que nos devuelve un booleano si hay conexión o no, usa la librería Wininet

uses wininet;
function Net_IsConnected: boolean;
const
 // local system uses a modem to connect to the Internet.
 INTERNET_CONNECTION_MODEM      = 1;
 // local system uses a local area network to connect to the Internet.
 INTERNET_CONNECTION_LAN        = 2;
 // local system uses a proxy server to connect to the Internet.
 INTERNET_CONNECTION_PROXY      = 4;
 // local system's modem is busy with a non-Internet connection.
 INTERNET_CONNECTION_MODEM_BUSY = 8;

var
 dwConnectionTypes : DWORD;
begin
 dwConnectionTypes := INTERNET_CONNECTION_MODEM +
 INTERNET_CONNECTION_LAN +
 INTERNET_CONNECTION_PROXY;
 Result := InternetGetConnectedState(@dwConnectionTypes,0);
end;

su uso es muy simple

if (Net_IsConnected) Then showmessage('hay conexión a internet');

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Google Analytics Alternative