Print Page | Close Window

Internet Detection

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=14587
Printed Date: 09 May 2024 at 8:15am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Internet Detection
Posted By: tralfaz
Subject: Internet Detection
Date 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!



Replies:
Posted By: SuperMario
Date Posted: 21 June 2009 at 12:26pm
No, Toolkit does not have any such methods.


Posted By: JantjeKeizer
Date 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.


Posted By: tralfaz
Date Posted: 21 June 2009 at 4:30pm
Could you show me how you did that? Thanks!


Posted By: adrien
Date 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

-------------
http://www.wingate.com - http://www.wingate.com


Posted By: PPL1
Date 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



Posted By: JantjeKeizer
Date 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


Posted By: tralfaz
Date 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.


Posted By: terrym
Date 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


Posted By: tralfaz
Date 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


Posted By: JantjeKeizer
Date 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


Posted By: terrym
Date 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


Posted By: znakeeye
Date 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/


Posted By: JantjeKeizer
Date 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...


Posted By: terrym
Date 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


Posted By: znakeeye
Date 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/


Posted By: terrym
Date 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


Posted By: terrym
Date 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


Posted By: JantjeKeizer
Date 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.


Posted By: znakeeye
Date 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.
 
http://www.vedivi.com/support/blog/72-configure-your-firewall-in-c.html - http://www.vedivi.com/support/blog/72-configure-your-firewall-in-c.html


-------------
PokerMemento - http://www.pokermemento.com/


Posted By: znakeeye
Date 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/


Posted By: terrym
Date 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.
 
http://www.vedivi.com/support/blog/72-configure-your-firewall-in-c.html - http://www.vedivi.com/support/blog/72-configure-your-firewall-in-c.html
 
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


Posted By: terrym
Date 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


Posted By: znakeeye
Date 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/


Posted By: terrym
Date 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


Posted By: znakeeye
Date Posted: 26 June 2009 at 5:22am
http://www.gershnik.com/faq/manage.asp#internet - http://www.gershnik.com/faq/manage.asp#internet

-------------
PokerMemento - http://www.pokermemento.com/


Posted By: znakeeye
Date Posted: 26 June 2009 at 5:45am
How about this?
 


-------------
PokerMemento - http://www.pokermemento.com/


Posted By: znakeeye
Date 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/


Posted By: terrym
Date 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


Posted By: terrym
Date 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


Posted By: Smucker
Date Posted: 01 July 2009 at 2:02pm
You might want to try http://msdn.microsoft.com/en-us/library/ms738520%28VS.85%29.aspx - 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)




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net