Re: Is this computer connected to the Internet
- Posted by "Kat" <gertie at visionsix.com> Jul 31, 2005
- 613 views
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