Lazarus

Programming => General => Topic started by: Robert W.B. on March 17, 2014, 01:09:21 pm

Title: How to detect internet connection!
Post by: Robert W.B. on March 17, 2014, 01:09:21 pm
Hi. How can I detect that the computer is not connected to the internet in an easy way?

if (are you connected to the internet) then begin

showmessage('You are not connected to the internet so, i have to quit. Try again when You have internet access.');

exit;
end;

Title: Re: How to detect internet connection!
Post by: BigChimp on March 17, 2014, 01:16:31 pm
Have a look here:
http://forum.lazarus.freepascal.org/index.php/topic,17506.msg96697.html#msg96697

http://forum.lazarus.freepascal.org/index.php/topic,6098.msg112032.html#msg112032

http://wiki.lazarus.freepascal.org/fphttpclient#Get_external_IP_address
for inspiration and code
Title: Re: How to detect internet connection!
Post by: Paul Breneman on March 17, 2014, 02:03:26 pm
Most of the stuff on this resource page was when we used to use modems to access the Internet, but there are some items (near the bottom of the page) you might find useful:
http://brenemanlabs.com/iConnect.htm
Title: Re: How to detect internet connection!
Post by: marcov on March 18, 2014, 07:05:44 pm
Most of the stuff on this resource page was when we used to use modems to access the Internet, but there are some items (near the bottom of the page) you might find useful:
http://brenemanlabs.com/iConnect.htm

If you use win95 and NT4 daily, maybe. Most of us are trying to kill off Windows XP before the end of the month though.
Title: Re: How to detect internet connection!
Post by: c4rlosC on May 18, 2019, 06:46:02 pm
hello, someone knows how to program an internet connection detector in GNU / linux
Title: Re: How to detect internet connection!
Post by: winni on May 18, 2019, 07:58:57 pm
I  can show you how to detect if google is online:

Code: Pascal  [Select][+][-]
  1. uses ...., netdb;
  2.  
  3. function HostByName (const who : string; var IP : String): Boolean;  inline;
  4. Var H : THostEntry;
  5.   begin
  6.     result := ResolveHostByName(who,H);
  7.     if result then IP := HostAddrToStr(H.Addr) else IP := '';
  8.   end;
  9.  
  10. procedure TestGoogle;
  11. var msg, IP : string;
  12. begin
  13. if HostByName ('www.google.de', IP ) then msg := 'Google online IP ='+IP else
  14.                                                                     msg := ' Google not online';
  15. showmessage (msg);
  16. end;
  17.  
  18.  
  19.  

Perhaps this is enough
Title: Re: How to detect internet connection!
Post by: Thaddy on May 18, 2019, 08:08:07 pm
http://ip.thaddy.com (online 99.8% since 1998) This is a  text string, not html...
Title: Re: How to detect internet connection!
Post by: RAW on May 18, 2019, 08:35:59 pm
Quote
I  can show you how to detect if google is online:
I guess one website isn't enough, what if the google website is down or under attack or has got problems ...?
But this is the only way to check if an internet connection is possible. There is no piece of code that can do this without trying to get connected.

Normally it's not possible to detect if a internet connection ist possible. Even if I can connect to google right now, then there is no guaranty that it will work in 5 minutes or whenever ... depending on the security software the user uses.

Just in case there is some magician out there who can do it without establishing an internet connection, then PLEASE provide a link!  :D



Quote
http://ip.thaddy.com (online 99.8% since 1998) This is a  text string, not html...
Beautiful IP ... I love it  :P


Quote
Most of us are trying to kill off Windows XP before the end of the month though.
HERETIC  :P
Title: Re: How to detect internet connection!
Post by: 440bx on May 18, 2019, 11:08:01 pm
Just in case there is some magician out there who can do it without establishing an internet connection, then PLEASE provide a link!  :D
Here is a way that doesn't require YOU to establish an internet connection but, that doesn't mean the system didn't establish one for you.

Read this article
https://www.codeproject.com/Tips/67577/Check-for-an-active-Internet-connection (https://www.codeproject.com/Tips/67577/Check-for-an-active-Internet-connection)

The code is in C but, it's quite simple.  Porting it to Pascal should take very little time.

HTH.

PS: I haven't tried his method but, it looks reasonable and, seems to be along the lines of what you're asking for.
Title: Re: How to detect internet connection!
Post by: madref on May 18, 2019, 11:23:17 pm
Here is another example:
Code: Pascal  [Select][+][-]
  1. type
  2.   { TCheckInternet }
  3.   TCheckInternet = class(TFPHTTPClient)
  4.   public
  5.     class function Available(AServer: string='www.google.com'): boolean;
  6.   end;  // TCheckInternet
  7.  
  8.  
  9.  
  10. { TCheckInternet }
  11. class function TCheckInternet.Available(AServer: string): boolean;
  12. var
  13.   c: TCheckInternet;
  14. begin
  15.   Result := False;
  16.   c:=TCheckInternet.Create(nil);
  17.   try
  18.     try
  19.       c.ConnectToServer(AServer,80);
  20.       Result := True;
  21.     except
  22.     end;
  23.   finally
  24.     c.Free;
  25.   end;
  26. end;     // TCheckInternet.Available
  27.  
  28.  
  29.  
  30. function HasInternetConnection : boolean;
  31. begin
  32.   Result := TCheckInternet.Available();
  33. end;     // HasInternetConnection
  34.  
  35.  
  36.  
  37.  
  38. if HasInternetConnection then .....
Title: Re: How to detect internet connection!
Post by: RAW on May 19, 2019, 04:43:17 am
Quote
The code is in C but, it's quite simple.  Porting it to Pascal should take very little time.

Looks like everything for doing that is already on board...
Code: Pascal  [Select][+][-]
  1. unit JwaIpHlpApi;
  2.  
  3. function GetIpForwardTable(pIpForwardTable: PMIB_IPFORWARDTABLE; var pdwSize: ULONG;
  4.   bOrder: BOOL): DWORD; stdcall;
  5. {$EXTERNALSYM GetIpForwardTable}
I've never played around with this, thanks for the tip ...  :)
Title: Re: How to detect internet connection!
Post by: Thaddy on May 19, 2019, 11:33:03 am
PS: I haven't tried his method but, it looks reasonable and, seems to be along the lines of what you're asking for.
Well... I have tried it some ions ago that's why I have this service. (Actually two, one is more advanced and detects redirects, see much older postings for context).
Boils down to: the only way to test for an internet connection is by making a connection to a reliable server.
In my case I give you your ip for free.... 8-) and as a string...not polluted by any html.... :P

Also... well... check my websites....Boring...
Title: Re: How to detect internet connection!
Post by: 440bx on May 19, 2019, 12:06:56 pm
In my case I give you your ip for free.... 8-)
You're really funny.  Every internet connection you make has your ip.  So nice of you to give one's IP for free... a real Santa Ip you are. :)
Title: Re: How to detect internet connection!
Post by: metallaro1980 on May 19, 2019, 03:53:27 pm
i am using mine

Code: Pascal  [Select][+][-]
  1. function TForm1.CheckInternet:boolean;
  2. var mypro1 : tprocess;
  3. var tmplst : tstringlist;
  4. var zk:integer;
  5. var tmpbuffer:string;
  6. var okbuffer:string;
  7. var artmp : array of string;
  8. var recev : integer;
  9. begin
  10.   try
  11.   mypro1 := tprocess.Create(nil);
  12.   tmplst := tstringlist.create;
  13.   mypro1.Executable:= 'ping';
  14.   mypro1.Parameters.Add('-c 5');
  15.   mypro1.parameters.add('8.8.8.8');
  16.   mypro1.Options := mypro1.Options + [poWaitOnExit, poUsePipes];
  17.   mypro1.Execute;
  18.   tmplst.loadfromstream(mypro1.output);
  19.   okbuffer := '';
  20.  
  21.   for zk := 0 to tmplst.Count - 1 do
  22.   begin
  23.     tmpbuffer := tmplst[zk];
  24.     if (pos('received', tmpbuffer) > 0) then
  25.     begin
  26.       okbuffer := tmpbuffer;
  27.       break;
  28.     end;
  29.   end;
  30.  
  31.   if (okbuffer = '') then
  32.   begin
  33.     result := false;
  34.     exit;
  35.   end
  36.   else
  37.   begin
  38.     tmpbuffer := '';
  39.     artmp := okbuffer.Split(',');
  40.     okbuffer := '';
  41.     for zk := 0 to length(artmp) - 1 do
  42.     begin
  43.       if (pos('received', artmp[zk]) > 0) then
  44.       begin
  45.         okbuffer := trim(artmp[zk]);
  46.         break;
  47.       end;
  48.     end;
  49.     if (okbuffer = '') then
  50.     begin
  51.       result := false;
  52.       exit;
  53.     end
  54.     else
  55.     begin
  56.        okbuffer := replacestr(okbuffer, 'received', '');
  57.        okbuffer := trim(okbuffer);
  58.        if isnumber(okbuffer) then
  59.        begin
  60.          recev := strtoint(okbuffer);
  61.          if (recev = 0) then
  62.          begin
  63.            result := false;
  64.            exit;
  65.          end
  66.          else
  67.          begin
  68.            result :=  true;
  69.            exit;
  70.          end;
  71.  
  72.        end
  73.        else
  74.        begin
  75.          result := false;
  76.          exit;
  77.        end;
  78.     end;
  79.  
  80.   end;
  81.  
  82.  
  83.   finally
  84.     mypro1.Free;
  85.   end;
  86.  
  87.  
  88. end;                          

here my source of my program to detect the internet ip in Lazarus
http://andreaverdi.altervista.org/linux/GetIP.zip (http://andreaverdi.altervista.org/linux/GetIP.zip)

Title: Re: How to detect internet connection!
Post by: Thaddy on May 19, 2019, 04:38:48 pm
In my case I give you your ip for free.... 8-)
You're really funny.  Every internet connection you make has your ip.  So nice of you to give one's IP for free... a real Santa Ip you are. :)
No... external IP, and not even my direct IP. You are being silly. (or have not sufficient understanding how routing works)
Look up my original postings. Both links are still up after all those years. Also demonstrates the difference.  :-X :-X.... Plz take note... You deserve my mild insults...
And YES testing an internet connection can only be done through a full connection. Happens to be my job.. just in case...Anything else can be spoofed from a local network.
(Hence that site is fully static and doesn't need https)
Title: Re: How to detect internet connection!
Post by: 440bx on May 19, 2019, 04:51:04 pm
No... external IP, and not even my direct IP. You are being silly. (or have not sufficient understanding how routing works)
Look up my original postings. Both links are still up after all those years. Also demonstrates the difference.  :-X :-X.... Plz take note... You deserve my mild insults...
And YES testing an internet connection can only be done through a full connection. Happens to be my job.. just in case...Anything else can be spoofed from a local network.
(Hence that site is fully static and doesn't need https)
Your posts indicate that your job most likely consists in arguing about things you know nothing, it is likely due to your extensive experience in that area that it might very well be the only thing you do well.

Very impressive!

I enjoy the amusement (another thing you provide for free)... keep going :)
Title: Re: How to detect internet connection!
Post by: lucamar on May 19, 2019, 09:48:15 pm
FWIW, I always test against IANA reserved names: example.com, example.org, etc. Lessens the chance of a failed connection because a  host is down: something has to be very wrong for those to fail.
Title: Re: How to detect internet connection!
Post by: engkin on May 19, 2019, 11:24:01 pm
To test against example.com, or any other domain, this involves communicating with a DNS server to find the IP address (yes, UDP). I wonder if relying on testing against a specific DNS server, like google's 8.8.8.8, would be equal.

Edit:
To check for connectivity, I noticed Android phones use:
http://connectivitycheck.android.com/generate_204
Title: Re: How to detect internet connection!
Post by: sstvmaster on May 19, 2019, 11:44:48 pm
No it is not equal, in my opinion.

I think, if the machine have an misconfigured dns then you only know that only ip is working.
With test against dns you can be sure that both works.

Do you enter an IP address in the address field of the browser?
Title: Re: How to detect internet connection!
Post by: engkin on May 19, 2019, 11:57:58 pm
No it is not equal, in my opinion.
That is why I posted the question, I want to hear members' opinions.

I think, if the machine have an misconfigured dns then you only know that only ip is working.
With test against dns you can be sure that both works.
I see what you mean. What I propose does not rely on the configuration of the machine. The procedure will send a DNS query packet to a DNS server, 8.8.8.8 for instance, and wait for a valid reply.

I think the signature of the procedure is something like:
Code: Pascal  [Select][+][-]
  1. function CheckConnictivityUsingDNS(ADomain:String='www.google.com'; ADNSServer:String='8.8.8.8'): boolean;

Do you enter an IP address in the address field of the browser?
Sometimes I do!


Title: Re: How to detect internet connection!
Post by: metallaro1980 on May 20, 2019, 03:49:16 pm
i am using the dns of google for my lan...for my router.
i am bypassing the dns server of my ISP.
my program can find the external ip of my router (on my website there is a php script that shows your internet ip)

with linux if i want to check the internet connection i use ping -c 5 8.8.8.8
and with  wget -nv --spider url ->  i can check if a url is valid (reachable)

Title: Re: How to detect internet connection!
Post by: engkin on May 22, 2019, 07:01:34 pm
Here is a way that doesn't require YOU to establish an internet connection but, that doesn't mean the system didn't establish one for you.

This is fantastic. Thank you for pointing this one out.

Code: Pascal  [Select][+][-]
  1. unit useRoutingTable;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. {
  8. Pointed out by @440bx:
  9. https://forum.lazarus.freepascal.org/index.php/topic,23943.msg321556.html#msg321556
  10. }
  11. function IsInternetAvailable(): boolean;
  12.  
  13. implementation
  14. uses
  15.   Windows;
  16.  
  17. //constant and types from JwaIpHlpApi and JwaIpRtrMib
  18. const
  19.   ANY_SIZE = 1;
  20.  
  21. type
  22. {$PUSH}
  23. {$PACKENUM 4} // jediapilib.inc
  24.  
  25.   MIB_IPFORWARDROW = record
  26.     dwForwardDest: DWORD;
  27.     dwForwardMask: DWORD;
  28.     dwForwardPolicy: DWORD;
  29.     dwForwardNextHop: DWORD;
  30.     dwForwardIfIndex: DWORD;
  31.     dwForwardType: DWORD;
  32.     dwForwardProto: DWORD;
  33.     dwForwardAge: DWORD;
  34.     dwForwardNextHopAS: DWORD;
  35.     dwForwardMetric1: DWORD;
  36.     dwForwardMetric2: DWORD;
  37.     dwForwardMetric3: DWORD;
  38.     dwForwardMetric4: DWORD;
  39.     dwForwardMetric5: DWORD;
  40.   end;
  41.   //PMIB_IPFORWARDROW = ^MIB_IPFORWARDROW;
  42.  
  43.   MIB_IPFORWARDTABLE = record
  44.     dwNumEntries: DWORD;
  45.     table: array [0..ANY_SIZE - 1] of MIB_IPFORWARDROW;
  46.   end;
  47.   PMIB_IPFORWARDTABLE = ^MIB_IPFORWARDTABLE;
  48. {$POP}
  49.  
  50. function GetIpForwardTable(pIpForwardTable: PMIB_IPFORWARDTABLE; var pdwSize: ULONG;
  51.   bOrder: BOOL): DWORD; stdcall; external 'iphlpapi.dll';
  52.  
  53. function IsInternetAvailable(): boolean;
  54. var
  55.   bIsInternetAvailable: boolean = false;
  56.   dwBufferSize: DWORD = 0;
  57.   dwIndex: DWORD;
  58.   pRoutingTable: PMIB_IPFORWARDTABLE;
  59.   pByte: Windows.PBYTE;
  60.   dwRowCount: DWORD;
  61. begin
  62.   // Get the required buffer size
  63.   if (ERROR_INSUFFICIENT_BUFFER = GetIpForwardTable(nil, &dwBufferSize, false)) then
  64.   begin
  65.     pByte := GetMem(dwBufferSize);
  66.     if (pByte<>nil) then
  67.     begin
  68.       pRoutingTable := PMIB_IPFORWARDTABLE(pByte);
  69.       // Attempt to fill buffer with routing table information
  70.       if (NO_ERROR = GetIpForwardTable(pRoutingTable, dwBufferSize, false)) then
  71.       begin
  72.         dwRowCount := pRoutingTable^.dwNumEntries; // Get row count
  73.         // Look for default route to gateway
  74.         for dwIndex := 0 to  dwRowCount-1 do
  75.         begin
  76.           if (pRoutingTable^.table[dwIndex].dwForwardDest = 0) then
  77.           begin // Default route designated by 0.0.0.0 in table
  78.             bIsInternetAvailable := true; // Found it
  79.             break; // Short circuit loop
  80.           end;
  81.         end;
  82.       end;
  83.       FreeMem(pByte); // Clean up. Just say "No" to memory leaks
  84.     end;
  85.   end;
  86.   Result := bIsInternetAvailable;
  87. end;
  88.  
  89. end.
Title: Re: How to detect internet connection!
Post by: 440bx on May 22, 2019, 09:54:32 pm
This is fantastic. Thank you for pointing this one out.
I'm very pleased you liked it. 

I never gave the problem of determining whether an internet connection is available or not much thought but, I found the OP's question and @RAW's request interesting.  A little googling found that method in CodeProject and, it looked good.   

Thank you for posting a Pascal version.  It will come in handy.



Title: Re: How to detect internet connection!
Post by: ASerge on May 23, 2019, 04:47:46 am
This is fantastic. Thank you for pointing this one out.
This feature only means that your gateway is alive. If it has nothing to do with the Internet, then the result of the function too.
Title: Re: How to detect internet connection!
Post by: madref on May 23, 2019, 06:00:37 am
Here is a way that doesn't require YOU to establish an internet connection but, that doesn't mean the system didn't establish one for you.

This is fantastic. Thank you for pointing this one out.

Code: Pascal  [Select][+][-]
  1. unit useRoutingTable;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. {
  8. Pointed out by @440bx:
  9. https://forum.lazarus.freepascal.org/index.php/topic,23943.msg321556.html#msg321556
  10. }
  11. function IsInternetAvailable(): boolean;
  12.  
  13. implementation
  14. uses
  15.   Windows;
  16.  
  17. //constant and types from JwaIpHlpApi and JwaIpRtrMib
  18. const
  19.   ANY_SIZE = 1;
  20.  
  21. type
  22. {$PUSH}
  23. {$PACKENUM 4} // jediapilib.inc
  24.  
  25.   MIB_IPFORWARDROW = record
  26.     dwForwardDest: DWORD;
  27.     dwForwardMask: DWORD;
  28.     dwForwardPolicy: DWORD;
  29.     dwForwardNextHop: DWORD;
  30.     dwForwardIfIndex: DWORD;
  31.     dwForwardType: DWORD;
  32.     dwForwardProto: DWORD;
  33.     dwForwardAge: DWORD;
  34.     dwForwardNextHopAS: DWORD;
  35.     dwForwardMetric1: DWORD;
  36.     dwForwardMetric2: DWORD;
  37.     dwForwardMetric3: DWORD;
  38.     dwForwardMetric4: DWORD;
  39.     dwForwardMetric5: DWORD;
  40.   end;
  41.   //PMIB_IPFORWARDROW = ^MIB_IPFORWARDROW;
  42.  
  43.   MIB_IPFORWARDTABLE = record
  44.     dwNumEntries: DWORD;
  45.     table: array [0..ANY_SIZE - 1] of MIB_IPFORWARDROW;
  46.   end;
  47.   PMIB_IPFORWARDTABLE = ^MIB_IPFORWARDTABLE;
  48. {$POP}
  49.  
  50. function GetIpForwardTable(pIpForwardTable: PMIB_IPFORWARDTABLE; var pdwSize: ULONG;
  51.   bOrder: BOOL): DWORD; stdcall; external 'iphlpapi.dll';
  52.  
  53. function IsInternetAvailable(): boolean;
  54. var
  55.   bIsInternetAvailable: boolean = false;
  56.   dwBufferSize: DWORD = 0;
  57.   dwIndex: DWORD;
  58.   pRoutingTable: PMIB_IPFORWARDTABLE;
  59.   pByte: Windows.PBYTE;
  60.   dwRowCount: DWORD;
  61. begin
  62.   // Get the required buffer size
  63.   if (ERROR_INSUFFICIENT_BUFFER = GetIpForwardTable(nil, &dwBufferSize, false)) then
  64.   begin
  65.     pByte := GetMem(dwBufferSize);
  66.     if (pByte<>nil) then
  67.     begin
  68.       pRoutingTable := PMIB_IPFORWARDTABLE(pByte);
  69.       // Attempt to fill buffer with routing table information
  70.       if (NO_ERROR = GetIpForwardTable(pRoutingTable, dwBufferSize, false)) then
  71.       begin
  72.         dwRowCount := pRoutingTable^.dwNumEntries; // Get row count
  73.         // Look for default route to gateway
  74.         for dwIndex := 0 to  dwRowCount-1 do
  75.         begin
  76.           if (pRoutingTable^.table[dwIndex].dwForwardDest = 0) then
  77.           begin // Default route designated by 0.0.0.0 in table
  78.             bIsInternetAvailable := true; // Found it
  79.             break; // Short circuit loop
  80.           end;
  81.         end;
  82.       end;
  83.       FreeMem(pByte); // Clean up. Just say "No" to memory leaks
  84.     end;
  85.   end;
  86.   Result := bIsInternetAvailable;
  87. end;
  88.  
  89. end.
This doesn't work on a Mac... to bad  :'(
Title: Re: How to detect internet connection!
Post by: engkin on May 23, 2019, 08:55:44 am
This is fantastic. Thank you for pointing this one out.
This feature only means that your gateway is alive. If it has nothing to do with the Internet, then the result of the function too.
Did you use "If"?

It means the computer, to its best knowledge, has an interface to be used with any IP -like 8.8.8.8- that does not fit in the other entries of the routing table (not 127.0.0.*? nope. not 192.168.0.*? nope. what about 192.168.44.*? nope ...etc).

It is the "active route" with network destination value "0.0.0.0" when you type:
netstat -r

Can you give one example where this entry could exist without internet connection?



This doesn't work on a Mac... to bad  :'(
There must be a similar code for Mac and Linux. Look for retrieving the routing table.
Title: Re: How to detect internet connection!
Post by: RAW on May 23, 2019, 08:57:23 am
Quote
This doesn't work on a Mac... to bad  :'(
The WINDOWS API isn't working on a MAC?
Sue Apple !!!  :D
Title: Re: How to detect internet connection!
Post by: ASerge on May 23, 2019, 09:12:13 am
Can you give one example where this entry could exist without internet connection?
I. e. you apparently consider that the network without the Internet does not exist?
Title: Re: How to detect internet connection!
Post by: RAW on May 23, 2019, 09:27:48 am
Simple Example:

1. The code works great
2. If a patch cable is down it works great too ... so far ...
3. BUT the code cannot "see" if I cannot connect with my browser !!!

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   If IsInternetAvailable
  4.   Then Color:= clBlue
  5.   Else Color:= clBlack;
  6. end;

In most cases this can give a good result if someone connects to the internet with a router that is always connected and has no security software running. But in my case I simply opened a program that has no right to connect and then FIREFOX cannot reach a website anymore. As long as the program is in the background.
Title: Re: How to detect internet connection!
Post by: engkin on May 23, 2019, 09:32:37 am
Can you give one example where this entry could exist without internet connection?
I. e. you apparently consider that the network without the Internet does not exist?
The network with the router has a separate entry. If you control the settings of your router using 192.168.44.1, for instance, you'll have an entry in the routing table with network destination value of 192.168.44.0.

If your computer is part of a local network that holds 60 computers with IP numbers from 192.168.0.2-->61, you will have an entry with 192.168.0.0.

When your system discovers that your computer can reach 8.8.8.8 through your router on 192.168.44.1, it adds the 0.0.0.0 entry for you. It will delete this entry when it fails, or when 192.168.44.1 disconnects (hardware) or disappears (Software: ARP packets receive no response).
Title: Re: How to detect internet connection!
Post by: sstvmaster on May 23, 2019, 09:41:43 am
And here you can read how about Windows do that:

https://blog.superuser.com/2011/05/16/windows-7-network-awareness/
Title: Re: How to detect internet connection!
Post by: engkin on May 23, 2019, 09:42:46 am
In most cases this can give a good result if someone connects to the internet with a router that is always connected and has no security software running. But in my case I simply opened a program that has no right to connect and then FIREFOX cannot reach a website anymore. As long as the program is in the background.

Which means your software can pinpoint the reason to the user. It can tell if the whole system has no internet or only a probable firewall/AV setting affecting your application. It does not tell you if the server you are trying to reach is down.
Title: Re: How to detect internet connection!
Post by: engkin on May 23, 2019, 09:50:28 am
And here you can read how about Windows do that:

https://blog.superuser.com/2011/05/16/windows-7-network-awareness/

Older systems like Windows XP while they do not use *.msftncsi.com, you can still notice the 0.0.0.0 entry when they discover internet connection.
Title: Re: How to detect internet connection!
Post by: RAW on May 23, 2019, 09:51:18 am
Quote
It does not tell you if the server you are trying to reach is down.
Correct, the server is fine... at least right now ...  :)
Title: Re: How to detect internet connection!
Post by: engkin on May 23, 2019, 09:54:49 am
Quote
It does not tell you if the server you are trying to reach is down.
Correct, the server is fine... at least right now ...  :)
Blocking access to the server does not mean you do not have access to the internet.
Title: Re: How to detect internet connection!
Post by: RAW on May 23, 2019, 10:04:22 am
Quote
Blocking access to the server does not mean you do not have access to the internet.

The security software doesn't allow anybody (in this case FIREFOX) to connect to the internet. As long as the forbidden program is running. Internet access (hardware) is definitely possible, but for the normal user it doesn't make a difference. The reason is not visible to the user. I don't know if this is the same with the onboard Windows-Firewall, I never use the windows firewall. I think it's not trustworthy enough...  :)
Title: Re: How to detect internet connection!
Post by: engkin on May 23, 2019, 10:34:25 am
Quote
Blocking access to the server does not mean you do not have access to the internet.

The security software doesn't allow anybody (in this case FIREFOX) to connect to the internet. As long as the forbidden program is running. Internet access (hardware) is definitely possible, but for the normal user it doesn't make a difference. The reason is not visible to the user. I don't know if this is the same with the onboard Windows-Firewall, I never use the windows firewall. I think it's not trustworthy enough...  :)

I assume the security software would notify the user, and the user is smart enough the realize why the other software is blocked as well despite the fact that the computer does have access to the internet.

My previous post was about the other method of testing internet connectivity using a connection to a server, when that specific server is blocked.
Title: Re: How to detect internet connection!
Post by: 440bx on May 23, 2019, 02:56:53 pm
The security software doesn't allow anybody (in this case FIREFOX) to connect to the internet.
I thought things that did that were called malware....  :D
Title: Re: How to detect internet connection!
Post by: RAW on May 23, 2019, 05:54:10 pm
Quote
I thought things that did that were called malware....  :D
Definitely ... In this case malware that I really like to use !!!   :)
Title: Re: How to detect internet connection!
Post by: madref on May 23, 2019, 08:16:47 pm
Quote
This doesn't work on a Mac... to bad  :'(
The WINDOWS API isn't working on a MAC?
Sue Apple !!!  :D


Do you know how??? :P :D
Title: Re: How to detect internet connection!
Post by: RAW on May 24, 2019, 05:16:49 am
I'm working on it ... I let you know !!!
Title: Re: How to detect internet connection!
Post by: ASerge on May 24, 2019, 01:53:38 pm
When your system discovers that your computer can reach 8.8.8.8 through your router on 192.168.44.1, it adds the 0.0.0.0 entry for you. It will delete this entry when it fails, or when 192.168.44.1 disconnects (hardware) or disappears (Software: ARP packets receive no response).
Complete nonsense. Check in any LAN with the switch or the router. There are stations on the L3 switch or the router will have 0.0.0.0 as the default gateway. So again, all this function checks is that there is a default gateway and it is alive. With the Internet it is connected only if this gateway goes to the Internet, but this check is certainly not here. At home, this is usually the case, but as I said, a couple of stations and one router to the Internet provider - this is not the only possible network configuration.
Title: Re: How to detect internet connection!
Post by: engkin on May 24, 2019, 05:33:05 pm
Complete nonsense. Check in any LAN with the switch or the router. There are stations on the L3 switch or the router will have 0.0.0.0 as the default gateway. So again, all this function checks is that there is a default gateway and it is alive. With the Internet it is connected only if this gateway goes to the Internet, but this check is certainly not here. At home, this is usually the case, but as I said, a couple of stations and one router to the Internet provider - this is not the only possible network configuration.
You are right. If the computer is part of a WAN you will have that entry in your forwarding table.

You found a practical example where this method will not work. While it will work in most cases, it is not bulletproof. Probably I can still rely on it to indicate lack of internet.
TinyPortal © 2005-2018