1. Is this computer connected to the Internet

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 ...

new topic     » topic index » view message » categorize

2. Re: Is this computer connected to the Internet

> 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()


new topic     » goto parent     » topic index » view message » categorize

3. Re: Is this computer connected to the Internet

On 31 Jul 2005, at 15:40, Craig Welch wrote:

> 
> 
> 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 ...

I try a dns lookup:

--START IMPORT DLL PROCs AND FUNCs
constant WSOCK32 = open_dll("wsock32.dll")

constant dllWSAStartup = 
define_c_proc(WSOCK32,"WSAStartup",{C_LONG,C_LONG})
constant dllgethostbyname =  
define_c_func(WSOCK32,"gethostbyname",{C_POINTER},C_POINTER)
constant dllWSACleanup = define_c_proc(WSOCK32,"WSACleanup",{})
--END   IMPORT DLL PROCs AND FUNCs

----------------------------------------------------------------------------------------------------------------
--------

function dns_DNSToIP(sequence domain)
  atom memAdr,memRet
  sequence IP,strIP

  if equal(domain,lastdomain) then
    return lastip
  end if

  memAdr = allocate(408)
  c_proc(dllWSAStartup,{257,memAdr})
  free(memAdr)
  memAdr = allocate_string(domain)
  memRet = c_func(dllgethostbyname,{memAdr})
  free(memAdr)
  if memRet = 0 or peek4u(memRet+16) = 0 then
    return ""
  end if
  IP = 
{peek(peek4u(memRet+16)),peek(peek4u(memRet+16)+1),peek(peek4u(mem
Ret+16)+2),peek(peek4u(memRet+16)+3)}
  strIP = sprintf("%d.%d.%d.%d",IP)
  c_proc(dllWSACleanup,{})
  lastdomain = domain
  lastip = strIP
  return strIP
end function

----------------------------------------------------------------------------------------------------------------
----


It works for named domains, not dotted ip addresses.

I forget who wrote that snippet, but it wasn't me. 

Kat

new topic     » goto parent     » topic index » view message » categorize

4. Re: Is this computer connected to the Internet

On 31 Jul 2005, at 2:17, Greg Haberek wrote:

> 
> > 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.

But will that show if offline on a ethernet connection? My computer shows 
connected even if the dsl is unplugged.

Kat

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu