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

1

6

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;
                }
            }
        }
Lancers answered 29/11, 2012 at 11:59 Comment(2)
I think you will have to check with the enums NetworkInterfaceType when you do NetworkInterface.GetAllNetworkInterfaces()Nonviolence
I did, but it's not really clear about the 3G connection.Lancers
N
4

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.

Nealy answered 29/11, 2012 at 12:8 Comment(3)
it may be an ADSL or dialup connection. what best way to detect that. I think ADSL will be "NetworkInterfaceType.AsymmetricDsl"Lancers
@Lancers - A 3G connection will appear as a ADSL or Dialup connection. You are asking for the way to detect this, which is a subjective question, so what have you tried and why are you unhappy with it?Devan
@Ramhound, I updated my question. sorry for the misunderstanding.Lancers

© 2022 - 2024 — McMap. All rights reserved.