How to check network available

Sometimes we require to check whether the network is available or not, normally when are trying to do an Updated version check from our application or invoking a third party web service or any looking for any licence information / registration details from website etc.

This is a simple function which will return Network status using Ping Class.

using System.Net.NetworkInformation;
public bool IsNetworkAvailable()
{
	using (Ping ping = new Ping())
	{
		PingReply pingReply = ping.Send("www.google.com", 200);
		return pingReply.Status == IPStatus.Success;
	}
}
This entry was posted in .Net, .Net 3.0 / 3.5, Windows Forms and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>