How to detect working internet connection in C#?

Just use the plain function

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

that return true of false if the connection is up.

From MSDN:
A network connection is considered to be available if any network interface is marked “up” and is not a loopback or tunnel interface.

Keep in mind connectivity is not all, you can be connected to a local network and the router is not connected to the Internet for instance. To really know if you are connected to the internet try the Ping class.

Leave a Comment