Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to detect what kind of connection I'm using ? WiFi, 3G or Ethernet?

I'm trying to detect what kind of network connection I'm connected to. is it WiFi or 3G? is there a way to do that using c# win forms .net 2.0 or 4.0 ?

        foreach (NetworkInterface adapter in adapters)
        {
            if (adapter.OperationalStatus == OperationalStatus.Up)
            {
                if (adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
                {
                    lblNetworkType.Text = "you are using WiFi";
                    break;
                }
                else if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ppp)
                {
                    lblNetworkType.Text = "you are using 3G or ADSL or Dialup";
                    break;
                }
                else if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    lblNetworkType.Text = "you are using Ethernet";
                    break;
                }
            }
        }
like image 662
Arrabi Avatar asked Nov 29 '12 11:11

Arrabi


1 Answers

Unfortunately there isn't a 'neat' way to do this as such. A 3G connection will look the same as a ADSL or dialup connection (with the network type being PPP).

If you are certain that you'll only ever be on WiFi/3G, then you could check the information in the NetworkInterface class provided by GetAllNetworkInterfaces and treat it as 3G if the the interface type is PPP. But as I mentioned this is the same for other types of modem connection.

Edit: You may have some luck looking for "3G", "HSPA", "HSDPA", "Dongle" in the device name or description. But this'd only be a 'decent guess' rather than being absolutely certain.

like image 190
PhonicUK Avatar answered Oct 20 '22 05:10

PhonicUK