I have an hourly diagnostic check that runs on our servers, which includes a check that the server has internet connectivity.
Below is the code I use to ping a url (from http://stackoverflow.com/questions/11800958/using-ping-in-c-sharp), but it's producing intermittent results on both https://www.facebook.com
and https://www.google.com
. The poor results are actually experienced on both a dedicated hosted VM and a separate Azure VM:
public static bool PingHost(string nameOrAddress)
{
if (nameOrAddress.IsEmpty())
return false;
bool pingable = false;
Ping pinger = new Ping();
try
{
var hostNameOrAddress = nameOrAddress.Replace("http://", "").Replace("https://", "")
.Replace("/", "");
PingReply reply = pinger.Send(hostNameOrAddress);
pingable = reply.Status == IPStatus.Success;
}
catch
{
return false;
// Discard PingExceptions and return false;
}
return pingable;
}
What's concerning is that I have other diagnostic checks that test other third party urls, and they show as fine.
What is a more reliable way to check for general internet connectivity?