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.NetworkAvailabilityChangedSystem.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;
}
{
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;
}
}