determining if there is internet connection in windows

Started by
8 comments, last by BriarLoDeran 23 years, 9 months ago
Greetings, I am just wondering if anyone knows a Win32 or MFC function that returns whether or not a computer has an active internet connection (via a modem, lan, etc). Thanks, -> Briar LoDeran <- Edited by - BriarLoDeran on 7/20/00 2:17:10 PM
Advertisement
quote: Original post by BriarLoDeran

Greetings,

I am just wondering if anyone knows a Win32 or MFC function that returns whether or not a computer has an active internet connection (via a modem, lan, etc).

Thanks,
-> Briar LoDeran <-

Edited by - BriarLoDeran on 7/20/00 2:17:10 PM



I'm going to refer you off this site. goto CodeGuru, in the internet link you will find some info on this subject

Dave "Dak Lozar" Loeser

Edited by - Dak Lozar on July 21, 2000 8:57:44 AM
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
Dak Lozar:
That was helpful. It ended up leading me to the following functions:

InternetGetConnectedState()
InternetCheckConnection()

What I am interested in now is a way to determine when a connection begins. I will initially use one of the two functions above to determine if there is a connection, but, if they are NOT connected, short of continually calling these functions, how do I know when the user connects to the internet? Does windows pass a WM_xxx message or something similar? Does anyone know the method windows uses?

Thanks,
-> Briar LoDeran <-
quote:Original post by BriarLoDeran

Dak Lozar:
That was helpful. It ended up leading me to the following functions:

InternetGetConnectedState()
InternetCheckConnection()

What I am interested in now is a way to determine when a connection begins. I will initially use one of the two functions above to determine if there is a connection, but, if they are NOT connected, short of continually calling these functions, how do I know when the user connects to the internet? Does windows pass a WM_xxx message or something similar? Does anyone know the method windows uses?

Thanks,
-> Briar LoDeran <-


I''m not sure that I understand what your trying to do
With these two functions you can determine if the computer has an active internet connection. If you have a processs that needs to "wake up" when the user establishes a connection, then your going to have to sleep or poll or busy wait for that to happen.
I''m unaware of any window WM_XXX call in the API that will do this.
A timer and a call to the InternetCheckConnection() function should work.

If you let me know what your trying to do or what you want to do maybe I can help more. If your wanting to check for a connection and in the even the check returns FALSE then you can use the RasAPI.





Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
Dak Lozar:
First off, thank you Dave for being so willing to help! I guess I was a little vague. The program I am working on needs to have a feature that is similar to ICQ or aol instant messanger at startup. You have the option of starting the program when the computer starts up. If the user is connected to the internet at startup, the program begins immediately. If the user is NOT connected, they want the program to sit in the system tray until there is a connect, and then for it to start. Is the only way to determine when the user connects to poll periodically? I was kind of hoping there would be a callback function I could give to windows that would return when the user connected. Any input would be greatly appreciated!

-> Briar LoDeran <-

Edited by - BriarLoDeran on July 21, 2000 12:47:27 PM
It's just a wild guess, but maybe WM_RASDIALEVENT is what you're looking for?

Maybe you have to install a hook orso...
This method works like a trigger, and you don't have to use timers and stuff




Edited by - baskuenen on July 25, 2000 2:31:38 PM
Check the ip, if no connection it''ll be the local host one, 127.0.0.1 or something I can''t remeber but easy to find. If its not that there must be an internet connection.
Should work.

Thanks to my friend Tom for teaching me that trick.
quote:Original post by Seaman

Check the ip, if no connection it''ll be the local host one, 127.0.0.1 or something I can''t remeber but easy to find. If its not that there must be an internet connection.
Should work.

Thanks to my friend Tom for teaching me that trick.

This will work fine if there aren''t any NICs in the machine.
If there is a NIC then you can have as many as three IP Addresses for this machine.

e.g.
LOCALHOST = 127.0.0.1 (loopback)NIC       = 10.10.0.1 (this could be for a lan)DIALUP    = ###.###.###.### (modem) 


Technically you would have to iterate through all of these ip addresses and "weed" out the loopback and the lan addresses, to find the "real" internet connection. So, you can''t assume that if the ip != 127.0.0.1 that you have a internet connection in commercial software or software that you will distribute to other people.





Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
quote:Original post by baskuenen

It''s just a wild guess, but maybe WM_RASDIALEVENT is what you''re looking for?

Maybe you have to install a hook orso...
This method works like a trigger, and you don''t have to use timers and stuff




Edited by - baskuenen on July 25, 2000 2:31:38 PM


I suppose you could wait for this event to fire... but there really isn''t a guarantee that this is a internet connection, you can dial other machines with Ras.

I still hold that the safest way is to poll the IP Addresses on you the machine and wake up when you have a valid IP (excluding LANs and loopbacks)




Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
quote:Original post by BriarLoDeran

Dak Lozar:
First off, thank you Dave for being so willing to help! I guess I was a little vague. The program I am working on needs to have a feature that is similar to ICQ or aol instant messanger at startup. You have the option of starting the program when the computer starts up. If the user is connected to the internet at startup, the program begins immediately. If the user is NOT connected, they want the program to sit in the system tray until there is a connect, and then for it to start. Is the only way to determine when the user connects to poll periodically? I was kind of hoping there would be a callback function I could give to windows that would return when the user connected. Any input would be greatly appreciated!

-> Briar LoDeran <-

Edited by - BriarLoDeran on July 21, 2000 12:47:27 PM



Sorry for the delay in responding...
You may have read my 2 post prior to this but, I will reiterate.
I think youll have to poll the IP Addresses for the machine and parse oout the IP''s that aren''t valid as internet addresses. The Ras message at first glance may seem to be the answer but, the possibility exists for the user to call another machine using Ras... someone correct me if I am wrong.

HTH


Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous

This topic is closed to new replies.

Advertisement