Recent

Author Topic: is there an internet connection?  (Read 4464 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1180
Re: is there an internet connection?
« Reply #15 on: February 04, 2023, 11:43:49 am »
Unfortunately I do not know, how to send a ping by Lazarus and how to grab its results.

Curt Carpenter in post #9 already gave you a link.

paweld

  • Hero Member
  • *****
  • Posts: 966
Re: is there an internet connection?
« Reply #16 on: February 04, 2023, 12:02:36 pm »
You can use the Indy package
Best regards / Pozdrawiam
paweld

af0815

  • Hero Member
  • *****
  • Posts: 1284
Re: is there an internet connection?
« Reply #17 on: February 04, 2023, 12:22:59 pm »
It is possible to make it with synapse (from OPM), i use it under win, linux, linux-arm,...

Code: Pascal  [Select][+][-]
  1. uses
  2.   pingsend;
  3.  
  4. const
  5.   MaxPingCnt = 5;
  6.  
  7. procedure PingServerSilent(const HostIP: String; var IsOk: Boolean);
  8. var
  9.   cnt: Integer;
  10.   aPing: TPINGSend;
  11. begin
  12.   aPing:= TPINGSend.Create;
  13.   try
  14.     aPing.Timeout:=500;
  15.     cnt := MaxPingCnt;
  16.     aPing.Sock.SocksTimeout:= 500;
  17.     while not aPing.Ping(HostIP) and (cnt > 0) do begin
  18.       dec(cnt);
  19.       sleep(10);
  20.     end;
  21.     IsOk := (cnt > 0);
  22.   finally
  23.     aPing.Free;
  24.   end;
  25. end;
  26.  
regards
Andreas

Thaddy

  • Hero Member
  • *****
  • Posts: 14169
  • Probably until I exterminate Putin.
Re: is there an internet connection?
« Reply #18 on: February 04, 2023, 12:50:29 pm »
Please do stop with advising ping as a reliable solution. Really, most servers drop ping requests.
Simply try to connect to example.com which is IANA itself.
« Last Edit: February 04, 2023, 12:52:29 pm by Thaddy »
Specialize a type, not a var.

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: is there an internet connection?
« Reply #19 on: February 04, 2023, 03:37:30 pm »
Please do stop with advising ping as a reliable solution. Really, most servers drop ping requests.
Simply try to connect to example.com which is IANA itself.

Yes!  ;D

Also if only http/https connections are being made, they might be using a proxy, and there might not be any actual Internet route (in which case no pings would work at all, even for servers on the Internet that reply to ping requests).

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Re: is there an internet connection?
« Reply #20 on: February 04, 2023, 05:38:57 pm »
The "anti-pingites" raise an interesting question:  how would one go about finding out a rough measure of the number of the world's servers that refuse pings?  And if it is a regional thing?  Same for ntp. Is it a big number?  I have no idea.

If nothing else, you can ping your own router, if there is one -- and that may or may not answer Nicole's question.  It would at least offer a clue as to the probability of an internet connection.

I've been hacking away on the net since the 90s and Mosaic and have never had a problem finding something ping-able or ntp-able -- but all in the U.S..   Ping floods are so '90s anymore anyway that the security achieved by disallowing pings and ntps is hardly worth it:  if your server is blocking them, ask them to stop!

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: is there an internet connection?
« Reply #21 on: February 04, 2023, 05:54:06 pm »
The "anti-pingites" raise an interesting question:  how would one go about finding out a rough measure of the number of the world's servers that refuse pings?  And if it is a regional thing?  Same for ntp. Is it a big number?  I have no idea.

I not completely an "anti-pingite"... I of course use it when troubleshooting connections.
I just don't use it for generalize automated checks to see if I have a connection (I do it use it for checking my own remote servers in specialized checks).

I've also worked at places (1990s, 2000s, 2010s, even 2020s) that were proxy only for all outgoing Internet connections, so there was not way to ping servers outside the company network. (and of course worked at places where the outside servers could be pinged).
« Last Edit: February 04, 2023, 05:58:49 pm by Bogen85 »

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: is there an internet connection?
« Reply #22 on: February 04, 2023, 06:03:05 pm »
There are a variety of "what is my IP address" sites...

Having a check that uses a list of those and returns TRUE on first successful transaction, and FALSE on not being able to complete a transaction with any of them could be a good general approach for checking for an Internet connection...

It would be checking a variety of things (DNS, access to external sites, etc) needed to make outgoing connections.

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: is there an internet connection?
« Reply #23 on: February 04, 2023, 06:08:32 pm »
Google's famous server 8.8.8.8 always responds to ping requests 24/7.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: is there an internet connection?
« Reply #24 on: February 04, 2023, 07:22:00 pm »
There is an inherent problem in determining the existence of an internet connection. 

The problem is, its existence is not guaranteed in any way.   If there is/was a connection, it can "vanish" at any time before it is used.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

dseligo

  • Hero Member
  • *****
  • Posts: 1180
Re: is there an internet connection?
« Reply #25 on: February 04, 2023, 07:37:53 pm »
Google's famous server 8.8.8.8 always responds to ping requests 24/7.

And so is 8.8.4.4. I use these because they are easy to remember and when you are having DNS problems, ping those two can reveal that in seconds.
I don't know why ping is so frown on.

af0815

  • Hero Member
  • *****
  • Posts: 1284
Re: is there an internet connection?
« Reply #26 on: February 04, 2023, 07:48:36 pm »
Thaddy says it not a so good idea to use ping for this. Yes, a lot of companies block ping for a good reason.

A defined request to a known site with https is a good soloution, M$ itself use such a request for checking the connection. But if you have no server for this of your own, you must use the "poor man" version with ping. (or try to reach google,...) 
« Last Edit: February 04, 2023, 07:50:10 pm by af0815 »
regards
Andreas

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: is there an internet connection?
« Reply #27 on: February 04, 2023, 07:50:57 pm »
I don't know why ping is so frown on.

Because they are not a comprehensive solution for an Internet resource access check...
Ability to access resources on the Internet often does not rely on routed access for every protocol to those resources.
Yes, for many (most?) home users, hotel/airport Internet users, workplace place internet users, that is the case... (routed access works).

But not always for every protocol in every setup...

I'm not going to force my home access to not be fully routed (it is through NAT though), but I can't guarantee that everywhere else I use the Internet that pings will work, as experience travelling and at some places I've worked at, pings don't work.
Rare that they don't, but I don't consider the places they don't work as one off oddball situations.

As such, I won't ever recommend pinging as a general method for an automated internet resource access check.
Specific to certain use cases, sure, but not as general reliable access check method.
« Last Edit: February 04, 2023, 08:00:18 pm by Bogen85 »

Curt Carpenter

  • Sr. Member
  • ****
  • Posts: 396
Re: is there an internet connection?
« Reply #28 on: February 04, 2023, 07:52:48 pm »
Quote
The problem is, its existence is not guaranteed in any way. 

The problem is, to paraphrase Lewis Carroll, that existence in general is not guaranteed in any way :)

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: is there an internet connection?
« Reply #29 on: February 04, 2023, 09:25:16 pm »
The problem is, to paraphrase Lewis Carroll, that existence in general is not guaranteed in any way :)
Indeed the existence problem is not specific to the internet (unfortunately ;) )
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018