I have trawled this forum and have found many threads about this topic but none of them seem to categorically propose an ideal and fool proof solution to determine an internet connection for both Mac and Windows.
As such I have listed the various solutions I have found and would be extremely appreciateive if people could vote on the one they think is best and perhaps explain why.
Also, I will actually be using the new framework xojo.net.HTTPSocket for better security and for HTTP 1.1 protocol so please let me know if any of these solutions or any others will not work for that.
dim h as new HTTPSocket call h.Get("http://www.google.com/", 5) if h.HTTPStatusCode = 200 then Return True Else Return False end if
Dim http As New HTTPSocket HTTP.Address = "www.apple.com" http.port = 80 http.Connect if http.LastErrorCode = 0 then Return True Else Return False end if http.close
Dim ipAddress As String ipAddress = System.Network.LookupIPAddress("google.com") If ipAddress <> "" Then Return True Else Return False End If
4. (Apparently this only tells you if the computer is connected to a LAN)
5. (Not for Mac)
Function CheckInternet() As Boolean #if TargetWin32 then Declare Function InternetGetConnectedState Lib "WinInet" ( ByRef state as Integer, reserved as Integer ) as Boolean Dim n as Integer if InternetGetConnectedState( n, 0 ) then return True else return False end if #else return False #endif End Function
Dim sh As New Shell sh.Mode = 0 sh.Execute("ping ns1.google.com -n 1") If InStr(0, sh.Result, "Pinging") > 0 Then Return True Return False
Dim socket As New HTTPSocket socket.yield = True dim ih as InternetHeaders = (socket.GetHeaders("http://www.google.com", 1)) return (ih <> nil)