I am in the process of developing a cloud backup software. The application is a desktop application developed using C#.

I need to add an option to stop/pause the backup if the computer was connected to a 3G network to save cost for the user.

I cannot seem to be able to find any example on how this can be achieved, there are some examples for Windows Phone and Windows Store Apps but I cannot find anything that can check if the connection type is a WiFi/Ethernet or 3G the latter is my main concern.

I tried a test application to enumerate the networks:

Console.WriteLine("checking network interfaces\n");

NetworkInterface[] interfaces =  NetworkInterface.GetAllNetworkInterfaces();

foreach (var networkInterface in interfaces)
{
   Console.WriteLine("Interface Detected");
   Console.WriteLine("Description: "+networkInterface.Description);
   Console.WriteLine("ID: " + networkInterface.Id);
   Console.WriteLine("Name: " + networkInterface.Name);
   Console.WriteLine("Interface Type: " + networkInterface.NetworkInterfaceType);
   Console.WriteLine("Operational Status: " + networkInterface.OperationalStatus.ToString());
   Console.WriteLine("Speed: " + networkInterface.Speed.ToString());
   Console.WriteLine("Supports Multicast: " + networkInterface.SupportsMulticast.ToString());
   Console.WriteLine("#########################################################\n");
}

The above code list my 3G connection as PPP which can be either ADSL or 3G. I am not sure if I can differentiate using some other options or APIs

I need a clear way to distinguish between those networks and so far I cannot find a way of doing so.

Can someone please help?

Dani AI

Generated

Short answer for : use the platform APIs where possible (they know about WWAN) and fall back to the IP/NDIS info only when necessary. On Windows 8+ consume the Windows.Networking.Connectivity APIs; on Windows 7 use the Mobile Broadband (MBN) Win32 API; as a last resort read adapter IfType via the IP Helper (GetIfEntry2/GetAdaptersAddresses) and look for WWAN IfType values. (learn.microsoft.com)

Practical Windows 8+ pattern (C# desktop can call these WinRT APIs): get the internet profile, then check IsWwanConnectionProfile / IsWlanConnectionProfile or inspect NetworkAdapter.IanaInterfaceType (IANA types are stable — handle unknown values defensively). Example:

using Windows.Networking.Connectivity;

var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile != null) {
  if (profile.IsWwanConnectionProfile) { /* cellular */ }
  else if (profile.IsWlanConnectionProfile) { /* wifi */ }

  var iana = profile.NetworkAdapter?.IanaInterfaceType ?? 0;
  // treat 243/244 as WWAN in logic if needed
}

These properties are provided by the WinRT networking API. (learn.microsoft.com)

Windows 7 / native fallback: use the Mobile Broadband (MBN) COM interfaces (IMbnInterfaceManager / IMbnInterface) to enumerate actual mobile-broadband devices and their state — this is the most reliable way to detect a cellular modem on Win7. If you must examine adapters, call GetIfEntry2 / GetAdaptersAddresses and check the IfType field (NDIS/IANA provides WWAN-specific values). If IfType is generic PPP, combine that check with device description / PnP ID or MBN results to disambiguate PPPoE vs a cellular modem. (learn.microsoft.com)

Practical advice: treat the connection’s cost info as authoritative for backup decisions — use ConnectionProfile.GetConnectionCost and pause when the cost is Fixed/Variable, roaming, or OverDataLimit. Also expose a user override as suggested (allow explicit “pause on mobile/metered” setting) so edge cases are handled without false positives. (learn.microsoft.com)

Might not be what you want, but , you could just ask whoever logs into the cloud what their connection type is. Or even if they want the ability to pause the connection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.