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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

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
deshawAuthor Commented:
I have solved my issue by using NetworkAddressChanged and NetworkAvailabilityChanged event.
Thanks.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Wireless Hardware

From novice to tech pro — start learning today.