Baldrick wrote:Assuming you are using a physical landline connection you could just unplug that from your router WAN connection to take your public IP & carrier signal out without losing your LAN connection which should up to a point replicate an isp fault.

Okay, I just unplugged my phone line from my router and tested the following code snippets to see which would correctly report no internet connection. Interestingly, only the last one, the InternetCheckConnection API call, was correct in the shortest time period (and smallest in size to code), but it took about 15 seconds to determine it. That's far too long to be practical, but since it's the only correct reliable method, I'll have to use it.

I wonder if a shorter timeout can be set for it somehow?
Code: Select all
Procedure Online()
d$="test" : b$=Space(SizeOf(ICMP_ECHO_REPLY)+Len(d$)+SizeOf(character)) : hIcmpFile=IcmpCreateFile_()
ProcedureReturn IcmpSendEcho_(hIcmpFile,1776375249,@d$,Len(d$),0,@b$,Len(b$)+SizeOf(ICMP_ECHO_REPLY),1000)
EndProcedure
Procedure TestInternetConnection()
connection=OpenNetworkConnection("www.google.com", 80)
If connection
CloseNetworkConnection(connection)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
InitNetwork()
connectionName$=Space(256)
tf=InternetGetConnectedStateEx_(@lpdwFlags.l,@connectionName$,256,0)
If tf
conn$=connectionName$
If lpdwFlags & #INTERNET_CONNECTION_CONFIGURED : conn$+", valid connection but might/might not be currently connected" : EndIf
If lpdwFlags & #INTERNET_CONNECTION_OFFLINE : conn$+", is in offline mode" : EndIf
If lpdwFlags & #INTERNET_RAS_INSTALLED : conn$+", RAS installed" : EndIf
If lpdwFlags & #INTERNET_CONNECTION_PROXY : conn$+", uses a proxy server" : EndIf
If lpdwFlags & #INTERNET_CONNECTION_LAN : conn$+", uses a local area network" : EndIf
If lpdwFlags & #INTERNET_CONNECTION_MODEM : conn$+", uses a modem" : EndIf
Else
conn$="No internet connection detected"
EndIf
Debug conn$ ; Returns "LAN Connection, RAS installed, uses a local area network".
Debug InternetGetConnectedState_(0,0) ; Returns 1 (wrong!).
Debug Online() ; Returns 1 (wrong!).
Debug TestInternetConnection() ; Returns 0 after 20 seconds.
Debug InternetCheckConnection_("http://www.google.com",1,0) ; Returns 0 after 15 seconds -- THE WINNER! :)