![]() |
Internet Detection |
Post Reply ![]() |
Author | ||
tralfaz ![]() Groupie ![]() Joined: 21 June 2009 Status: Offline Points: 36 |
![]() ![]() ![]() ![]() ![]() 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! |
||
![]() |
||
SuperMario ![]() Admin Group ![]() ![]() Joined: 14 February 2004 Status: Offline Points: 18057 |
![]() ![]() ![]() ![]() ![]() |
|
No, Toolkit does not have any such methods.
|
||
![]() |
||
JantjeKeizer ![]() Groupie ![]() Joined: 12 February 2008 Status: Offline Points: 70 |
![]() ![]() ![]() ![]() ![]() |
|
I had the same problems, then I simply tried pinging google, which has proven to be enough in my case.
|
||
![]() |
||
tralfaz ![]() Groupie ![]() Joined: 21 June 2009 Status: Offline Points: 36 |
![]() ![]() ![]() ![]() ![]() |
|
Could you show me how you did that? Thanks!
|
||
![]() |
||
adrien ![]() Senior Member ![]() Joined: 30 April 2007 Location: New Zealand Status: Offline Points: 449 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
PPL1 ![]() Groupie ![]() Joined: 10 April 2006 Location: Canada Status: Offline Points: 70 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
JantjeKeizer ![]() Groupie ![]() Joined: 12 February 2008 Status: Offline Points: 70 |
![]() ![]() ![]() ![]() ![]() |
|
But it's not always reliable. The way I do it now is WSAStartup then gethostbyname and then WSACleanup |
||
![]() |
||
tralfaz ![]() Groupie ![]() Joined: 21 June 2009 Status: Offline Points: 36 |
![]() ![]() ![]() ![]() ![]() |
|
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. |
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
tralfaz ![]() Groupie ![]() Joined: 21 June 2009 Status: Offline Points: 36 |
![]() ![]() ![]() ![]() ![]() |
|
but what if Google.com goes away (just kidding, haha)
Nice and simple, I'll give it a shot. Thank you, Tra |
||
![]() |
||
JantjeKeizer ![]() Groupie ![]() Joined: 12 February 2008 Status: Offline Points: 70 |
![]() ![]() ![]() ![]() ![]() |
|
If that's not important, then this is a good solution |
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
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/
|
||
![]() |
||
JantjeKeizer ![]() Groupie ![]() Joined: 12 February 2008 Status: Offline Points: 70 |
![]() ![]() ![]() ![]() ![]() |
|
|
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
#include <Wininet.h>
#pragma comment(lib, "wininet")
BOOL isConnected = InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM, 0); |
||
PokerMemento - http://www.pokermemento.com/
|
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
JantjeKeizer ![]() Groupie ![]() Joined: 12 February 2008 Status: Offline Points: 70 |
![]() ![]() ![]() ![]() ![]() |
|
|
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
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/
|
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
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/
|
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
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/
|
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
PokerMemento - http://www.pokermemento.com/
|
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
How about this?
IsNetworkAlive(NETWORK_ALIVE_WAN)
|
||
PokerMemento - http://www.pokermemento.com/
|
||
![]() |
||
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
|
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/
|
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
|
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 |
||
![]() |
||
Smucker ![]() Senior Member ![]() ![]() Joined: 02 February 2008 Status: Offline Points: 156 |
![]() ![]() ![]() ![]() ![]() |
|
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) |
||
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |