News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Check for internet connection

Started by Magnum, October 10, 2011, 04:38:56 PM

Previous topic - Next topic

FORTRANS

Quote from: dedndave on October 11, 2011, 12:11:41 AM
yah - it should work

this one seems to fly...

Hi,

   Here are my results.

HTH,

Steve


Fresh reboot, cable not plugged in.

G:\WORK>test34
00000000 00000010
Press any key to continue ...

Plugged cable into live DSL modem with no internet.

G:\WORK>test34
00000001 00000012
Press any key to continue ...

Waited for internet connection to come up.

G:\WORK>test34
00000001 00000012
Press any key to continue ...

dedndave

just as i suspected

however, if you look at the link that Jochen posted, it's only the first step...

http://www.masm32.com/board/index.php?topic=17520.msg147244#msg147244

that part is merely used to avoid the connection dialog
the next step is InternetOpenURL

if (InternetGetConnectedState(...) == FALSE)
{
    // Don't attempt connection or it will bring up the dialog
    ...
}
else
{
    //Attempt connection
    if (InternetOpenURL(...) == NULL)
    {
        // Call failed
        err = GetLastError();
        if ((err == ERROR_INTERNET_NAME_NOT_RESOLVED) ||
            (err == ERROR_INTERNET_CANNOT_CONNECT) ||
            (err == ERROR_INTERNET_TIMEOUT))
        {
            // probably not connected...handle appropriately
            ...
        }
    }
    // We're connected!!!
    ....
}


i think some code is missing, like InternetOpen, InternetCloseHandle   :P

dedndave

rather than doing all that...

InternetGetConnectedState
InternetCheckConnection

look ma, no handle   :bg

dedndave

#33
this works for me
if i have a connection to the router, but the router is not connected to the internet, it returns FALSE

        .XCREF
        .NOLIST
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\wininet.inc
        INCLUDELIB \masm32\lib\wininet.lib
        .LIST

IFNDEF FLAG_ICC_FORCE_CONNECTION
FLAG_ICC_FORCE_CONNECTION EQU 1
ENDIF

IsOnline PROTO  :LPSTR

        .DATA

szURL   db 'http://www.google.com',0

;-------------------------------------------------------------------------

        .CODE

_main   PROC

        INVOKE  IsOnline,offset szURL
        print   uhex$(eax),13,10
        inkey
        exit

_main   ENDP

;-------------------------------------------------------------------------

IsOnline PROC   lpszURL:LPSTR

;Test Internet Connection - DednDave, 10-2011
;
;lpszURL points to a zero-terminated test URL string (must start with "http://")
;
;Returns EAX = FALSE if not connected
;        EAX = TRUE if connected

        push    eax
        mov     edx,esp
        INVOKE  InternetGetConnectedState,edx,0
        or      eax,eax
        jz      IsOnl0

        INVOKE  InternetCheckConnection,lpszURL,FLAG_ICC_FORCE_CONNECTION,0

IsOnl0: pop     edx
        ret

IsOnline ENDP

;-------------------------------------------------------------------------

        END     _main

baltoro

You can also use WMI (Windows Management Instrumentation) to determine various hardware configuration properties of your local machine. Check out: CIM Studio. CIM Studio is a free MSDN utility that is the easiest tool for browsing WMI. CIM Studio is available as part of the WMI tools.
The well-known assembly genius,...EDGAR,...has posted an example for accessing the WMI interface in assembly language: WMI. WARNING: WMI is a COM interface, and, always runs as an out-of-proc COM server...it requires a special COM security setting, which EDGAR demonstrates in his code example. Here is an explanation of COM activation: How Does COM Activation Work Anyway?
Baltoro

dedndave

#35
that worked great
had cable service drop out for about half an hour
ran this little program to tell me when it came back on   :bg

;build as a WINDOWS app

        .XCREF
        .NOLIST
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\wininet.inc
        INCLUDELIB \masm32\lib\wininet.lib
        .LIST

;-------------------------------------------------------------------------

IsOnline PROTO   :LPSTR

;-------------------------------------------------------------------------

IFNDEF FLAG_ICC_FORCE_CONNECTION
FLAG_ICC_FORCE_CONNECTION EQU 1
ENDIF

;-------------------------------------------------------------------------

        .CODE

IsOnline PROC    lpszURL:LPSTR

;Test Internet Connection
;
;lpszURL points to a zero-terminated test URL string (must start with "http://")
;
;Returns EAX = FALSE if not connected
;            = TRUE if connected
;        EDX = connection description (see InternetGetConnectedState documentation)

        push    eax
        mov     edx,esp
        INVOKE  InternetGetConnectedState,edx,0
        or      eax,eax
        jz      IsOnl0

        INVOKE  InternetCheckConnection,lpszURL,FLAG_ICC_FORCE_CONNECTION,0

IsOnl0: pop     edx
        ret

IsOnline ENDP

;-------------------------------------------------------------------------

szURL   db 'http://www.google.com',0

;-------------------------------------------------------------------------

_main   PROC

loop00: INVOKE  IsOnline,offset szURL
        or      eax,eax
        jz      loop00

        INVOKE  Beep,750,1000
        exit

_main   ENDP

;-------------------------------------------------------------------------

        END     _main