How to find out if you’re connected to the Internet

I want to write a Windows application that does something when I disconnect from the Internet . I was thinking of writing a very simple C # / Delphi application that just checks every 20 seconds to see if I am still connected.

If I need to interrogate, I would really like the solution, apart from trying to download a web page from the web. I cannot assume that trying to download means "offline", as there may be other applications that consume internet bandwidth. In addition, I am sure that a constant connection / download from a specific site will block my IP address.

I am sure there is a way to find out if it is connected without downloading / connecting to a remote server , but I'm not sure how to do it.

+3
source share
3 answers

, : , -, , , , , ? , , .
, , API InternetGetConnectedState , .
, , , ZoneAlarm " -", , .

Delphi:

procedure IsConnected;
var
  dwFlags: DWORD;
begin
  if InternetGetConnectedState(@dwFlags, 0) then
  begin
    if (dwFlags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM  then
      ShowMessage('Modem Connection')
    else
    if (dwFlags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then
      ShowMessage('LAN Connection')
    else
    if (dwFlags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY then
      ShowMessage('Connection thru Proxy')
    else
    if (dwFlags and INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE then
      ShowMessage('Local system in offline mode')
    else
    if (dwFlags and INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED then
      ShowMessage('Valid connection exists, but might or might not be connected')
  end
  else
    ShowMessage('Not Connected. Try to connect and risk of being prompted to dial into another Internet Service Provider.');
end;
+10

It seems that this can be done using the method described here: http://www.csharphelp.com/archives3/archive499.html

+2
source

Source: https://habr.com/ru/post/1702225/


All Articles