2

I know that you can check for network connectivity, but I can't seem to find a way to check if there is truly internet available, short of a ping. I know of a few use cases where a user would be connected to a local WLAN which doesn't have access to the internet, and I would prefer to avoid a timeout on request.

Short of pinging, which would take a rather long time to complete depending on the network connectivity, is there a way to explicitly test for internet?

SBoss
  • 8,845
  • 7
  • 28
  • 44
  • http://stackoverflow.com/questions/13617017/windows-phone-8-connection-handler-internet-availability – Rohit Jul 23 '13 at 07:30
  • @Kyle: That will return true even if you're in a local connection. – SBoss Jul 23 '13 at 07:37
  • possible duplicate of [What is the best way to check for Internet connectivity using .Net?](http://stackoverflow.com/questions/2031824/what-is-the-best-way-to-check-for-internet-connectivity-using-net) – Alexander Jul 23 '13 at 07:41
  • @Alexander I know this question is old, but as the OP tagged WP8, I do not think that question fits as a duplicated question. Like DeMama answer, pinging won't work on the phone. – Malavos Apr 25 '14 at 19:25

2 Answers2

1

you can try this ....

var asd = NetworkInterface.GetInternetInterface();

I hope this might help ...

Sandeep Chauhan
  • 1,313
  • 1
  • 10
  • 23
0

Use the Ping class (Only works if the server you are trying to reach has ping enabled.

public bool checkNet()
{
    bool kleir = false;
    using (Ping ping = new Ping())
    {
        try
        {
            if (ping.Send("yourDomain.com", 2000).Status == IPStatus.Success)
            {
                kleir = true;
            }
        }
        catch (PingException)
        {
            kleir = false;
        }
    }
    return kleir;
}
DeMama
  • 1,134
  • 3
  • 13
  • 32
  • you can't always ping a domain/website even if you are online, ping it's a program that relies on certain prerequisite, it's not 100% reliable and it's not part of the protocol either. – user2485710 Jul 23 '13 at 07:35
  • True, if the server has `ping` disabled, this won't work. I'll edit my post. – DeMama Jul 23 '13 at 07:37
  • 3
    Also, (the question is tagged WP8) Windows phone does not has the Ping() class so this anwser will not work on windowsphone – Bart Teunissen Aug 01 '13 at 13:19