Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Internet Detection
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Internet Detection

 Post Reply Post Reply
Author
Message
tralfaz View Drop Down
Groupie
Groupie


Joined: 21 June 2009
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote tralfaz Quote  Post ReplyReply Direct Link To This Post Topic: Internet Detection
    Posted: 21 June 2009 at 11:04am
Hi

I need to know if the computer is connected to the internet.
I'm using Windows calls like:     (FARPROC&)InetIsOffline = GetProcAddress(hURL, _T("InetIsOffline"));

This barely works. Most of the time when my wifi is turned off, or cable unplugged, it still says I'm connected.

Question: are there internet connection routines in the Toolkit? If so, are there examples?

Thanks!
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2009 at 12:26pm
No, Toolkit does not have any such methods.
Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2009 at 3:37pm
I had the same problems, then I simply tried pinging google, which has proven to be enough in my case.
Back to Top
tralfaz View Drop Down
Groupie
Groupie


Joined: 21 June 2009
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote tralfaz Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2009 at 4:30pm
Could you show me how you did that? Thanks!
Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2009 at 2:21am
There's an "Event" SDK in windows from windows 2000 onwards that you can use to determine things like whether you have connectivity or not, and gives you indications when people log in or off, and power events (like going from utility to UPS power).

Other options are to do things like use IPHelper APIs to enumerate the system route table to see if you have a route to a host or not.

I presume you want something that won't

a) block
b) cause a dial

Cheers

Adrien
Back to Top
PPL1 View Drop Down
Groupie
Groupie


Joined: 10 April 2006
Location: Canada
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote PPL1 Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2009 at 1:01pm
I use this function, and it works fine:
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long

 Public Function IsOnline() As Boolean
  Dim LFlags As Long
  IsOnline = InternetGetConnectedState(LFlags, 0&)
End Function

Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post Posted: 23 June 2009 at 3:08am
Originally posted by PPL1 PPL1 wrote:

I use this function, and it works fine:Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long Public Function IsOnline() As Boolean  Dim LFlags As Long  IsOnline = InternetGetConnectedState(LFlags, 0&)End Function
I tried that, too.
But it's not always reliable.
The way I do it now is WSAStartup then gethostbyname and then WSACleanup
Back to Top
tralfaz View Drop Down
Groupie
Groupie


Joined: 21 June 2009
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote tralfaz Quote  Post ReplyReply Direct Link To This Post Posted: 23 June 2009 at 10:47am
I tried  IsOnline = InternetGetConnectedState(LFlags, 0&)

It's not reliable at all. I can unplug the cable and it still thinks its online. I think it caches something.

I'll try the other suggestions. Thanks guys.
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2009 at 9:13am

if ( InternetCheckConnection( "http://www.google.com", FLAG_ICC_FORCE_CONNECTION, 0 ) return TRUE;

this has worked for us without problems
 
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
tralfaz View Drop Down
Groupie
Groupie


Joined: 21 June 2009
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote tralfaz Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2009 at 9:37am
but what if Google.com goes away (just kidding, haha)

Nice and simple, I'll give it a shot. Thank you,  Tra
Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2009 at 11:01am
Originally posted by terrym terrym wrote:


if ( InternetCheckConnection( "http://www.google.com", FLAG_ICC_FORCE_CONNECTION, 0 ) return TRUE;



this has worked for us without problems

 
This indeed works, but requires Windows 2000 Professional or better.
If that's not important, then this is a good solution
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2009 at 1:02pm
True, but I guess as we only support from Windows 2000 SP4+ we do not have that issue.
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 2:46am
Pinging Google is a very ugly solution. Imagine if all applications did this. Soon you end up with a DoS attack...
PokerMemento - http://www.pokermemento.com/
Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 3:46am
Originally posted by znakeeye znakeeye wrote:

Pinging Google is a very ugly solution. Imagine if all applications did this. Soon you end up with a DoS attack...
I agree, but it was the best I could come up with for Win9x. It's the lack of alternatives. Not that it really justifies it, but still...
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 4:49am
That was the problem here, we just needed to detect if we had a connection (a real connection) and this was the only reliable method we could find :(  if anybody knows of a better reliable method we will happily change our code :)
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 4:52am
#include <Wininet.h>
 
#pragma comment(lib, "wininet")

BOOL isConnected = InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM, 0);
PokerMemento - http://www.pokermemento.com/
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 4:57am
Originally posted by znakeeye znakeeye wrote:

#include <Wininet.h>
 
#pragma comment(lib, "wininet")

BOOL isConnected = InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM, 0);
 
Postitive we tried this, and the problem we found was if we disconnected the network cable it would still report as connected?
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 4:58am
but will definately give this a go, once we have discovered :( why the White ribbon theme is not working :( on our application but it is in the Ribbon Sample SDI application
 
hopefully when Oleg replies to our support ticket he will have a solution as posted video to forum to show stange problem
 
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 4:58am
Originally posted by terrym terrym wrote:

Originally posted by znakeeye znakeeye wrote:

#include <Wininet.h>
 

#pragma comment(lib, "wininet")BOOL isConnected = InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM, 0);



 

Postitive we tried this, and the problem we found was if we disconnected the network cable it would still report as connected?

Same here.
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 4:58am
Also, you might want to check some firewall settings before firing up a homepage etc. If you don't, some users will block your application. I believe the best approach is to notify the user before connecting to the Internet the first time.
 
PokerMemento - http://www.pokermemento.com/
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:01am
You're right.
"A return value of TRUE from InternetGetConnectedState indicates that at least one connection to the Internet is available. It does not guarantee that a connection to a specific host can be established."
 
Have to do some research here. It seems odd that such a simple task is that hard...
PokerMemento - http://www.pokermemento.com/
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:02am
Originally posted by znakeeye znakeeye wrote:

Also, you might want to check some firewall settings before firing up a homepage etc. If you don't, some users will block your application. I believe the best approach is to notify the user before connecting to the Internet the first time.
 
 
Cool we will add this to our range of software over the coming months as a great idea.
 
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:04am
Originally posted by znakeeye znakeeye wrote:

You're right.
"A return value of TRUE from InternetGetConnectedState indicates that at least one connection to the Internet is available. It does not guarantee that a connection to a specific host can be established."
 
Have to do some research here. It seems odd that such a simple task is that hard...
 
Tell us about it, we had trouble finding a solution for a task that should have been very simple.  Then we stumbled upon the method we use as above, which has worked perfectly but like you say we'd prefer a better solution.
 
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:05am
I believe this is the right way of doing this:
InternetCheckConnection(NULL, FLAG_ICC_FORCE_CONNECTION, 0);
 
Who uses OS < Win2k??
PokerMemento - http://www.pokermemento.com/
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:08am
Originally posted by znakeeye znakeeye wrote:

I believe this is the right way of doing this:
InternetCheckConnection(NULL, FLAG_ICC_FORCE_CONNECTION, 0);
 
Who uses OS < Win2k??
 
We have also tried this method and it must have also failed in some circumstances.  However yes I agree our applications require Windows 2000 (SP4+) and soon we will even drop Windows 2000 support.
 
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:22am
PokerMemento - http://www.pokermemento.com/
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 5:45am
How about this?
 
IsNetworkAlive(NETWORK_ALIVE_WAN)
PokerMemento - http://www.pokermemento.com/
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 26 June 2009 at 6:30am
In my own software, I keep my WINVER set to 0x500, but I don't perform any tests on Win2k. That is, it should work in Win2k, but no guarantees. I think it's fair enough.
 
 
Did you test the function in my previous post?
PokerMemento - http://www.pokermemento.com/
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 27 June 2009 at 10:20am
Hi
 
Sorry not had chance as been trying to fix white theme.  However will definately try this on monday, thanks
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Posted: 28 June 2009 at 10:30am
Originally posted by tralfaz tralfaz wrote:

but what if Google.com goes away (just kidding, haha)

Nice and simple, I'll give it a shot. Thank you,  Tra
 
Personally we check 3 main sites: Google, Microsoft and Yahoo to make sure ;)
Thank you,
Terry Mancey

email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
Back to Top
Smucker View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 February 2008
Status: Offline
Points: 156
Post Options Post Options   Thanks (0) Thanks(0)   Quote Smucker Quote  Post ReplyReply Direct Link To This Post Posted: 01 July 2009 at 2:02pm
You might want to try GetAddrInfo() for several known hosts. This will avoid connecting to anything but the DNS server(s). Unfortunately, if the DNS server is on a local network system, or all addresses are cached (there or on your local system) it might give back a valid address even though outbound connections are down.

You might want to experiment with sending it invalid or reserved IPV4 addresses; these may force a connection to a real (external) DNS server, and the error returns may be different depending on the local system's (or local network's) actual connection to the internet. I haven't experimented with that.

Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.