Jump to content
JohnLM

Am I connected to the Internet - how can I find out?

Recommended Posts

Specs: Delphi XE7, 11 and 12,  VCL, Win7/10 

 

I work mainly on my win7 latop.  And there is this file that I check for stats purpsoes every day and throughout the day as I am working on the laptop.  And in one instance today, it dawned on me that I need to know if I was connected to the internet or not.  Plus, a side bonus could be helpful to know that if I lose internet I could do something about it. 

 

In win7 I noticed that in the bottom task tray area, there is the icon, the one with the square monitor looking image (sure its different in win10), when I hover the mouse over it or click on it, it will say, "Internet access

 

Is there some delphi code-snippet already out there that will tell me that I am connected to the internet, like in the above mentioned?

Share this post


Link to post

On Windows, you can use the Network List Manager API, specifically the INetworkListManager.isConnectedToInternet property.

 

However, as there are so many different ways that a PC can be connected to the Internet nowadays, you are better off simply trying to access an online resource (such as your status file) and see if it succeeds or fails, don't even bother polling the Internet status beforehand.  That just introduces a TOCTOU race condition.

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

ICS includes an TIcsInetAlive component to check for IPv4 and/or IPv6 internet connectivity, using Ping and/or HTTP, to the same Microsoft servers that Windows uses to detect the internet, www.msftconnecttest.com and ipv6.msftconnecttest.com.

 

Angus

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×