> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# Check internet connectivity in UWP
- URL: https://developerinsider.co/check-internet-connectivity-in-uwp/
- Published: 2016-03-13T09:31:54.000Z
- Updated: 2018-09-15T13:01:01.000Z
- Author: Vineet Choudhary
- Tags: Windows

In this article you will learn, how to check Internet connection availability, Internet connection availability via WWLA(WiFi) or WWAN (Mobile), check whether device connected to a metered network or not and sense the significant network availability changes.

## 1\. Check Internet Connection Availability

To check whether internet connected or not use `GetIsNetworkAvailable` method of `NetworkInterface` class.

```c#
bool isInternetConnected = NetworkInterface.GetIsNetworkAvailable();

```

> **GetIsNetworkAvailable()** \-  
> **Summary:** Indicates whether any network connection is available.  
> **Returns:** `true` if a network connection is available; otherwise, `false`.

## 2\. Check Internet Connection Availability via WWLN (WiFi)

To check whether internet connected via WWAN use `IsWlanConnectionProfile` property of `ConnectionProfile` class

```c#
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
bool isWLANConnection = (InternetConnectionProfile == null)?false:InternetConnectionProfile.IsWlanConnectionProfile;

```

> **IsWlanConnectionProfile**  
> **Summary:** Gets a value that indicates if connection profile is a WLAN (WiFi) connection. This determines whether or not  
> WlanConnectionProfileDetails is null.  
> **Returns:** Indicates if the connection profile represents a WLAN (WiFi) connection.

## 3\. Check Internet Connection Availability via WWAN (Mobile)

To check whether internet connected via WWAN use `IsWwanConnectionProfile` property of`ConnectionProfile` class

```c#
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();    
bool isWLANConnection = (InternetConnectionProfile == null)?false:InternetConnectionProfile.IsWwanConnectionProfile;

```

> **IsWwanConnectionProfile**  
> **Summary:** Gets a value that indicates if connection profile is a WWAN (mobile) connection. This determines whether or not WwanConnectionProfileDetails is null.  
> **Returns:** Indicates if the connection profile represents a WWAN (mobile) connection.

## 4\. Check Metered network

To check whether Internet reachable via a metered connection or not, use `GetConnectionCost` method on `NetworkInterface` class.

```c#
var connectionCost = NetworkInformation.GetInternetConnectionProfile().GetConnectionCost();
if (connectionCost.NetworkCostType == NetworkCostType.Unknown 
        || connectionCost.NetworkCostType == NetworkCostType.Unrestricted)
{
    //Connection cost is unknown/unrestricted
}
else
{
   //Metered Network
}

```

## 5\. Manage network availability changes

To sense the significant network availability changes, use event`NetworkStatusChanged` of `NetworkInformation` class

```c#
// register for network status change notifications
 networkStatusCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChange);
 if (!registeredNetworkStatusNotif)
 {
     NetworkInformation.NetworkStatusChanged += networkStatusCallback;
     registeredNetworkStatusNotif = true;
 }
async void OnNetworkStatusChange(object sender)
{
    // get the ConnectionProfile that is currently used to connect to the Internet                
    ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
    if (InternetConnectionProfile == null)
    {
        await _cd.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage);
        });
    }
    else
    {
        connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);
        await _cd.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            rootPage.NotifyUser(connectionProfileInfo, NotifyType.StatusMessage);
        });
    }
    internetProfileInfo = "";
}

```

**References**

- [https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj835820.aspx](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj835820.aspx?ref=developerinsider.co)
- [https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452991.aspx](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452991.aspx?ref=developerinsider.co)
- [https://msdn.microsoft.com/en-us/library/windows/apps/xaml/JJ835821(v=win.10).aspx](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/JJ835821%28v=win.10%29.aspx?ref=developerinsider.co)
- [https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.networking.connectivity.networkcosttype.aspx](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.networking.connectivity.networkcosttype.aspx?cs-save-lang=1&cs-lang=csharp&ref=developerinsider.co#code-snippet-1)