Link to home
Start Free TrialLog in
Avatar of deshaw
deshawFlag for India

asked on

Monitor the internet connectivity continuesly

Hi,

I am looking for the robust way to monitor the internet connectivity using C# application. I know that I can do it using periodically pinging some site but I want to do it robust way so that my application should able to detect the internet connectivity lost event in a moment.

The intension behing this to monitor the user has been connected to office or not using VPN or wireless connection. My application should be able to tell me immediately whenever I connect and discoonect from the office/internet. If this helps to you. When I connect to office, I will have another interface along with ISP provider IP with predefined IP address range say 124.45.xx.xx( though IP isnot a real one).

Any alternative suggestion would also be appreciated.

Thanks.
Avatar of manavsi
manavsi
Flag of India image

May be try something like this..

HTH
Manavsi
try
{
System.Net.IPHostEntry = System.Net.Dns.GetHostByName("www.google.com"); // ur ip or domain here...
return true;
}
catch
{
return false; // host not reachable.
} 

Open in new window

Correction:

Manavsi
System.Net.IPHostEntry objIPHE = System.Net.Dns.GetHostByName("www.google.com");

Open in new window

you also try one of these.. which will also work...
HttpWebRequest req;
HttpWebResponse resp;
try
{
     req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
     resp = (HttpWebResponse)req.GetResponse();
 
     if(resp.StatusCode.ToString().Equals("OK"))
     {
         Console.WriteLine("its connected.");
     }
     else
     {
         Console.WriteLine("its not connected.");
 
     }
}
catch(Exception exc)
{
     Console.WriteLine("its not connected.");
}
 
// You should include the finally clause with
 
finally
{
    resp.Close();
}
 
// Otherwise, this doesn't work on a loop or timer. If u r using one... :)

Open in new window

Avatar of Rob Williams
There is a great little inexpensive application for this. It was called IP Monitor, but now Net Gong. It will monitor multiple IP's. Ideally you want to use a local IP as a reference, your router, the ISP's gateway, and an Internet IP. When it fails this will help you to isolate where the failure is. The application keeps an HTML log of lost connectivity, and can be set to send audible, screen, or e-mail notifications, as soon as lost connectivity is detected. As I recall the connectivity test can be set to increments of one minute, but not less than 1 minute. If interested they have a 30 day trial period.
http://netgong.tsarfin.com/overview.html
Avatar of deshaw

ASKER

manavsi, thanks for reply but I already mentined that I know how to get the connectivity. My main concern it to monitor it in robust way. Please read the question carefully.
Thanks.
Avatar of deshaw

ASKER

Robwill, i think we don't need any such application. I just want to make my application to identify in the next moment of connectivity (any of interface disconnected) lost. Thats it.
Thanks.
ASKER CERTIFIED SOLUTION
Avatar of deshaw
deshaw
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial