Re: Is this computer connected to the Internet
- Posted by Greg Haberek <ghaberek at gmail.com> Jul 31, 2005
- 715 views
> Can anyone suggest a way that a Euphoria program can, by way of a system > call, determine if the computer is presently connected to the Internet? > Other than by trying to access a web page ... Searching MSDN works wonders. This allows your Win32Lib app to determine what type of connection is present. Multiple values are or'ed together. A return value of 0 (false) or INTERNET_CONNECTION_OFFLINE would show there is no connection available. HTH, ~Greg
-- Test for an Internet connection include Win32Lib.ew global constant wininet = registerw32Library( "wininet.dll" ), xInternetGetConnectedState = registerw32Function( wininet, "InternetGetConnectedState", {C_POINTER,C_LONG}, C_INT ) global constant -- values for lpdwFlags INTERNET_CONNECTION_MODEM = #01, INTERNET_CONNECTION_LAN = #02, INTERNET_CONNECTION_PROXY = #04, INTERNET_CONNECTION_MODEM_BUSY = #08, -- no longer used INTERNET_RAS_INSTALLED = #10, INTERNET_CONNECTION_OFFLINE = #20, INTERNET_CONNECTION_CONFIGURED = #40 global function InternetGetConnectedState() -- check for an internet connection atom lpdwFlags, dwReserved, retv lpdwFlags = allocate( 4 ) dwReserved = 0 =09 retv = w32Func( xInternetGetConnectedState, {lpdwFlags, dwReserved} ) if retv = w32True then retv = peek4u( lpdwFlags ) end if =09 free( lpdwFlags ) =09 return retv end function constant StateDesc = { -- connection state descriptions {INTERNET_CONNECTION_MODEM, "Local system uses a modem to connect to the Internet."}, {INTERNET_CONNECTION_LAN, "Local system uses a local area network to connect to the Internet."}, {INTERNET_CONNECTION_PROXY, "Local system uses a proxy server to connect to the Internet."}, {INTERNET_CONNECTION_MODEM_BUSY, "No longer used."}, {INTERNET_RAS_INSTALLED, "Local system has RAS installed."}, {INTERNET_CONNECTION_OFFLINE, "Local system is in offline mode."}, {INTERNET_CONNECTION_CONFIGURED, "Local system has a valid connection to the Internet," & " but it might or might not be currently connected."}} global function InternetGetConnectedDesc() -- gets a text description of internet connection atom state sequence desc =09 state = InternetGetConnectedState() =09 desc = "" for i = 1 to length(StateDesc) do if and_bits( state, StateDesc[i][1] ) then desc &= StateDesc[i][2] & '\n' end if end for return desc end function puts( 1, InternetGetConnectedDesc() ) VOID = wait_key()