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.
LVL 1
deshawAsked:
Who is Participating?
 
deshawConnect With a Mentor Author Commented:
I have solved my issue by using NetworkAddressChanged and NetworkAvailabilityChanged event.
Thanks.
0
 
manavsiCommented:
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

0
 
manavsiCommented:
Correction:

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

Open in new window

0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
manavsiCommented:
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

0
 
Rob WilliamsCommented:
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
0
 
deshawAuthor Commented:
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.
0
 
deshawAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.