Ashwin N Bhanushali
Ashwin N Bhanushali

Reputation: 3882

Internet Connection Network type is it wi-fi/ethernet or something else.How to find programmatically in windows 8 metro app c#

I am developing app for windows 8 surface device. I need to find the internet connection type programmatically what i want to find is the device is connected to wi-fi/LanConnection or some other network type.

Thank You.

Upvotes: 2

Views: 2057

Answers (2)

vITs
vITs

Reputation: 1560

 WwanConnectionProfileDetails wlanConnectionProfileDetails = InternetConnectionProfile.WwanConnectionProfileDetails;

if (wlanConnectionProfileDetails != null)
{                            
status = true;
string accessPointName = wlanConnectionProfileDetails.HomeProviderId;
if (wlanConnectionProfileDetails.GetCurrentDataClass() == WwanDataClass.Edge || wlanConnectionProfileDetails.GetCurrentDataClass() == WwanDataClass.Gprs)
{
networkType = NetworkType.EDGE;
}
else if (wlanConnectionProfileDetails.GetCurrentDataClass() == wanDataClass.Hsdpa ||
wlanConnectionProfileDetails.GetCurrentDataClass() == WwanDataClass.Hsupa ||
wlanConnectionProfileDetails.GetCurrentDataClass() == WwanDataClass.Umts)
{
networkType = NetworkType.HSPA;
}
else if (wlanConnectionProfileDetails.GetCurrentDataClass() == WwanDataClass.LteAdvanced)
{
networkType = NetworkType.LTE;
}                            
}

This is how I did check type of data service connected to. Cheers!!

Upvotes: 1

Farhan Ghumra
Farhan Ghumra

Reputation: 15296

You can find network type with NetworkAdapter class. It has property IanaInterfaceType. To check all the IANA interface, go here

var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
if (profile != null)
{
    var interfaceType = profile.NetworkAdapter.IanaInterfaceType;

    // 71 is WiFi & 6 is Ethernet(LAN)
    if (interfaceType == 71 || interfaceType == 6)
    {
        //TODO:
    }
    // 243 & 244 is 3G/Mobile
    else if (interfaceType == 243 || interfaceType == 244)
    {
        //TODO:
    } 
}

Upvotes: 6

Related Questions