.NET: Checking whether an Internet connection is available

Posted By Venu Thomas

The method using ping checks whether there is an internet connection or not?

In C#.NET

The following namespace is required:

using System.Net.NetworkInformation;
/// <Summary>
/// Checks whether an Internet connection is available.
/// </Summary>
/// <Returns>
/// True / false
/// </Returns>
/// Site: WiseCodes.Com

public static bool wcCheckInternetConnectionStatus()
{
 Ping pingSender = new Ping();

 try
 {
PingReply pReply = pingSender.Send("www.microsoft.com", 100);

 return pReply.Status == IPStatus.Success;
 }
 catch
 {
 return false;
 }
}

Link: System.Net.NetworkInformation Namespace (Via MSDN)

Happy Programming!! ;-)

Tags: , ,

  •  
  • Share with others:

    Thanks for visiting us! If you enjoyed these icons please feel free to share them! Or if you want to know what's going on with WiseCodes.com, follow us!

    Leave a Reply

    Anti-Spam Protection by WP-SpamFree

    Locations of visitors to this page eXTReMe Tracker