How to check the Internet connection status?

Ask general questions here.
AutomationTester
Posts: 30
Joined: Mon Jan 21, 2013 1:31 pm

How to check the Internet connection status?

Post by AutomationTester » Mon Feb 11, 2013 1:33 pm

Hai,

Can you tell me, how to check the internet connection status(Active or inactive) through code?
Code should be in C#.

Thanks and Regards

Amir aka AutomationTester

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to check the Internet connection status?

Post by Support Team » Mon Feb 11, 2013 1:49 pm

Hi,
AutomationTester wrote:Can you tell me, how to check the internet connection status(Active or inactive) through code?
Code should be in C#.
Use following code
public static bool HasConnection()
{
    try
    {
        System.Net.IPHostEntry i = System.Net.Dns.GetHostEntry("www.google.com");
        return true;
    }
    catch
    {
        return false;
    }
}
FYI, it just took about 30 seconds to find this part of code using Google.

Regards,
Peter
Ranorex Team

AutomationTester
Posts: 30
Joined: Mon Jan 21, 2013 1:31 pm

Re: How to check the Internet connection status?

Post by AutomationTester » Tue Feb 12, 2013 7:45 am

Hai Peter,

Works like a Charm. Thanks :D

Thanks
Amir aka AutomationTester