check internet Connection c#
check internet connection availiblty in c# .net
Method 1.
bool ConnectionExists()
{
try
{
System.Net.IPHostEntry objIPHE = System.Net.Dns.GetHostEntry("www.google.com");
return true;
}
catch
{
return false;
}
}
Method 2.
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;
}
}
Blog by: VidyaGyan