What is the fastest and most efficient way to check for Internet connectivity in .NET?
NetworkInterface.GetIsNetworkAvailable
is very unreliable. Just have some VMware or other LAN connection and it will return wrong result.
Also about Dns.GetHostEntry
method I were just concerned about whether test URL might be blocked in the environment where my application going to deploy.
So another way I found out is using InternetGetConnectedState
method.
My code is
[System.Runtime.InteropServices.DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool CheckNet()
{
int desc;
return InternetGetConnectedState(out desc, 0);
}