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

Magnum

I would like a program to start based on whether there is a current internet connection.

How would I be able to check for that ?

Have a great day,
                         Andy

dedndave

i know just what you mean - lol

when i have a connection, i don't want any damned balloons popping up out of the task bar telling me so
when i do not have a connection, i want an alert telling me when it comes back on - only one alert   :P

baltoro

MAGNUM,   
I once wrote an application to do this in C++ and assembly. You can either check the Registry entries that are made by your network device, or you can use WMI (which is a COM interface) to do this. In my application, I did both, and found that it was reliable. The only annoying aspect of doing this is that you have to poll the data sources,...which means that once you activate the application, you are letting it run in the background.
I have forgotten exactly where the registry entries are located,...at the time, I had found a source on the Internet that described this operation, and I used SysInternals RegMon to verify the correct keys. When you are NOT connected to the Internet, these Registry keys (and the data values) are deleted from the Registry (at least that was how it worked with my machine -- Windows XP -- using the wireless network adapter).
...Let me search,...and, I'll see what I can find,...
Baltoro

Magnum

I came up with this, but it is not working.



.DATA

Connected   db   "Connected.",0
AppName     db   " ",0

.data?

l_RASCONN RASCONN 0FFh dup ({})
l_Buffer_Size dd ?
l_Conn_Count dd ?
hand1  dd ?
hand2  dd ?

.CODE

Start:

invoke RasEnumConnections, addr l_RASCONN, addr l_Buffer_Size, addr l_Conn_Count
mov  hand1,eax


invoke CreateEvent,0,FALSE,FALSE,0
mov  hand2,eax

invoke RasConnectionNotification,hand1,hand2,RASCN_Connection ; check if there is an internet connection

.IF (eax == 0)

invoke  MessageBox, NULL, addr Connected, addr AppName, MB_OK

.ENDIF


; invoke Sleep,3000 ; give the system enuf time to end the connection
                  ; don't want to leave the port in an inconsistent state.

invoke ExitProcess, 0

END Start
Have a great day,
                         Andy

Magnum

Quote from: baltoro on October 10, 2011, 05:44:47 PM
MAGNUM,   
I once wrote an application to do this in C++ and assembly. You can either check the Registry entries that are made by your network device,
...Let me search,...and, I'll see what I can find,...

I looked thru the registry to find any entries that are made when I am connected.

Could not find anything.

Have a great day,
                         Andy

baltoro

MAGNUM,
I didn't use that RasEnumConnections API in my code.
What I did was Google for the manufacturer name of my Network device, and then determine the correct Internet protocol that it uses.
And, yeah, the Registry entries are really obscure,...as I recall, I had no clue where they might be located until I found the info on the Web,...but, what I finally found was: Dynamic Host Configuration Protocol. I think if you do a Registry search for: DHCP when you are connected, you will it,...
I'm still searching, by the way,...
Sorry, I'm at a public terminal and it's logging me off
Baltoro

dedndave

there should be a simple way to ping something   :P
notice, that a viable connection to a router does not mean the internet is available
maybe you could ping http://www.google.com
they are pretty fast and reliable


NoCforMe

I would think that the registry would be the last place one would want to look for internet connection information.

Keep in mind that not all of us have networks. I have a dial-up connection; how would you go about determining if I'm connected? (Remember, you want a general solution that works for everyone, not just your computer and your internet connection.)

dedndave

be sure to look at the end of the page that ragdog linked for you
there is a little example that may be helpful

Magnum

Thanks to everyone.

I don't understand this. Can I use Null, or do I have to ping an actual internet address ?

If lpszUrl is NULL and there is an entry in the internal server database for the nearest server, the host value is extracted from the entry and used to ping that server.
Have a great day,
                         Andy

Magnum

invoke InternetCheckConnection,NULL,FLAG_ICC_FORCE_CONNECTION,0

gives me :

C:\masm32\SOURCE\Internet_Chk_Conn.asm(38) : error A2006:undefined symbol : FLAG_ICC_FORCE_CONNECTION
C:\masm32\SOURCE\Internet_Chk_Conn.asm(38) : error A2114:INVOKE argument type mismatch : argument : 2
Have a great day,
                         Andy


Magnum

I don't understand what this is.

I know that I want INTERNET_CONNECTION_MODEM.

lpdwFlags
[out] Pointer to a variable that receives the connection description. This parameter can be one or more of the following values.
Have a great day,
                         Andy

dedndave

i would define FLAG_ICC_FORCE_CONNECTION like this
IFNDEF  FLAG_ICC_FORCE_CONNECTION
FLAG_ICC_FORCE_CONNECTION EQU 1
ENDIF

that way, if a future version of windows.inc or wininet.inc has the flag, it will still assemble correctly
you might also make a mention in the masm32 windows.inc subforum - there are probably several similar flags missing, too
or you could just use "1"   :bg

QuotelpdwFlags
[out] Pointer to a variable that receives the connection description. This parameter can be one or more of the following values.

create a dword variable and pass the address of it to the function
after a successful call, the dword will hold one of those values