Here is a list of servers I would prefer to contact, but I do not know how. http://4.2.2.1 does not work.
https://sebastianhetzel.net/zuverlaessige-oeffentliche-dns-server/
As I said before, those are DNS servers.
However, they seem to be either
https://www.rfc-editor.org/rfc/rfc5966 or
https://www.rfc-editor.org/rfc/rfc7766 compliant, as they are accepting TCP connections on port 53.
If you don't care if they are working or not, but that you are merely able to connect to at least one, something like the following should work:
program checkdns_ex;
{$mode objfpc}
{$H+}
uses
baseunix, // needed for TTimeVal (what about windows?)
Sockets,
types;
function checkConnect (const hostAddress: string; portNumber: integer; timeout: integer = 3): Boolean;
var
sock: LongInt;
addr: TSockAddr;
timeset: TTimeVal; // is TTimeVal available on windows?
begin
sock := fpsocket(AF_INET, SOCK_STREAM, 0);
if sock = -1 then begin
result := false;
Exit;
end;
timeset.tv_sec := timeout;
timeset.tv_usec := 0;
fpsetsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, @timeset, SizeOf(timeset));
addr.sin_family := AF_INET;
addr.sin_port := htons(portNumber);
addr.sin_addr := StrToNetAddr(hostAddress);
result := 0 = fpconnect(sock, @addr, SizeOf(addr));
CloseSocket(Sock);
end;
function checkAnyConnect (const hosts: TStringDynArray; const port: integer = 53): boolean;
var
host: string;
begin
for host in hosts do if checkConnect(host, port) then exit(true);
result := false;
end;
begin
if checkAnyConnect([
'4.2.2.1',
'4.2.2.2',
'4.2.2.3',
'4.2.2.4',
'4.2.2.5',
'4.2.2.6']) then writeln('Connection Success')
else
writeln('Connection Failed');
end.
I don't have any Windows setup to test on, I tested on Linux. I'm not sure on Windows, I had to use
baseunix for the TTimeVal type definition to set a decent connection timeout.