views:

121

answers:

2

Our application downloads data from the internet using RSS but is having connection problems on machines connecting with 3G. We'd like to detect 3G,EDGE,GPRS connections so that we can change the application behaviour, display warnings or status of connection.

How would this be done?

+2  A: 

The NetworkInterface class in the System.Net.NetworkInformation namespace should be of some use to you (more specifically, the GetAllNetworkInterfaces method. An example is shown on the linked MSDN page that demonstrates how to get the type, address, operational status, and other information about every network interface.

Reduced version of MSDN example:

public static void ShowNetworkInterfaces()
{
    IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    Console.WriteLine("Interface information for {0}.{1}     ",
            computerProperties.HostName, computerProperties.DomainName);
    if (nics == null || nics.Length < 1)
    {
        Console.WriteLine("  No network interfaces found.");
        return;
    }

    Console.WriteLine("  Number of interfaces .................... : {0}", nics.Length);
    foreach (NetworkInterface adapter in nics)
    {
        IPInterfaceProperties properties = adapter.GetIPProperties();
        Console.WriteLine();
        Console.WriteLine(adapter.Description);
        Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'='));
        Console.WriteLine("  Interface type .......................... : {0}", adapter.NetworkInterfaceType);
        Console.WriteLine("  Physical Address ........................ : {0}", 
                   adapter.GetPhysicalAddress().ToString());
        Console.WriteLine("  Operational status ...................... : {0}", 
            adapter.OperationalStatus);

        Console.WriteLine();
    }
}
Noldorin
OK, but based on these properties, how can you tell if the network interface is 3G/EDGE/GPRS ? I tried to connect a 3G modem to my PC, the NetworkInterfaceType is "Ppp", which doesn't tell if it's a mobile connection.
Thomas Levesque
+1  A: 

Hi Matthew,
The NetworkInterface class doesn't support such detection yet.

A workaround could be: 3G connections tend to have a long response time (> 100ms). You could implement a ping check, and change the application behavior depending on the ping response time.

-rAyt

Henrik P. Hessel