public static bool IsInternetAvailable()
{
// The next line detects whether the computer is hooked up to a local network, wired or wireless.
// If it's not on a network at all, we know the Internet isn't available!
var networkConnected = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
if (!networkConnected)
{
_internetAvailable = false;
return false;
}
// Test whether we can talk to a known site of interest on the internet. This will tell us
// close enough whether or not the internet is available.
try
{
// test site same as what we use to talk to Amazon S3
var iNetRequest = (HttpWebRequest)WebRequest.Create("https://s3.amazonaws.com");
iNetRequest.Timeout = 2500;
var iNetResponse = iNetRequest.GetResponse();
iNetResponse.Close();
_internetAvailable = true;
return true;
}
catch (WebException ex)
{
_internetAvailable = false;
return false;
}
}