Isabella
---- I fell upon the thorn of life, I bleed.

To check for a network connection in .NET 2.0 use this:


System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

To monitor a change in IP address or a change in network availability, use the events from the NetworkChange class:


System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged

System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged

 

Or 

 

try
{
System.Net.IPHostEntry objIPHE = System.Net.Dns.GetHostEntry("www.google.com");

}
catch
{
MessageBox.Show ("...No Conn...");
}

 or

 

---------

bool ConnectionExists()
{
try
{
System.Net.Sockets.TcpClient clnt=new System.Net.Sockets.TcpClient("www.google.com",80);
clnt.Close();
return true;
}
catch(System.Exception ex)
{
return false;
}

} 

 

 

posted on 2012-01-03 10:20  李昀璟  阅读(239)  评论(0编辑  收藏  举报