Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check internet connection (availability) in Windows 8

How to check internet connection availability in Windows 8,C# development ? I looked at MSDN but page has been deleted.

like image 593
mert Avatar asked Nov 29 '12 11:11

mert


People also ask

How do I find available networks on my computer?

After your Surface restarts, sign in to Windows. Go to Start, and select Settings > Network & internet > Wi-Fi > Show available networks, and see whether your wireless network name appears in the list of available networks. If you see your wireless network name, select it and select Connect.


Video Answer


2 Answers

I use this snippet without problems:

public static bool IsInternet()
{
    ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
    bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
    return internet;
}
like image 52
Martin Suchan Avatar answered Sep 20 '22 05:09

Martin Suchan


I had to use GetConnectionProfiles() and GetInternetConnectionProfile() to make it work across all devices.

class ConnectivityUtil
{
    internal static bool HasInternetConnection()
    {            
        var connections = NetworkInformation.GetConnectionProfiles().ToList();
        connections.Add(NetworkInformation.GetInternetConnectionProfile());

        foreach (var connection in connections)
        {
            if (connection == null)
                continue;

            if (connection.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
                return true;
        }

        return false;
    }
}
like image 33
Joshua Heller Avatar answered Sep 23 '22 05:09

Joshua Heller