Forum > General
is there an internet connection?
Bogen85:
--- Quote from: Nicole on February 15, 2023, 09:11:56 pm ---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/
--- End quote ---
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:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.
Bogen85:
--- Quote from: Bogen85 on February 16, 2023, 06:39:20 am ---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.
--- End quote ---
On Windows it is likely winsock or winsock2 that is needed for TTimeVal.
GetMem:
--- Quote from: Bogen85 on February 16, 2023, 06:47:25 am ---
--- Quote from: Bogen85 on February 16, 2023, 06:39:20 am ---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.
--- End quote ---
On Windows it is likely winsock or winsock2 that is needed for TTimeVal.
--- End quote ---
With a small modification your code works on windows too. Here is a cross platform version, tested on Win10/Linux Mint 20.02, both 64 bit:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program checkdns_ex; {$mode objfpc}{$H+} uses Classes, Sysutils, Sockets, Types, {$IFDEF WINDOWS} Windows, Winsock; {$ELSE} BaseUnix, UnixType; {$ENDIF} 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 := TInAddr(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.
Navigation
[0] Message Index
[*] Previous page