有没有一种方法来检测我使用的是什么类型的连接? WIFI,3G或以太网? [英] Is there a way to detect what kind of connection I'm using ? WiFi, 3G or Ethernet?

查看:311
本文介绍了有没有一种方法来检测我使用的是什么类型的连接? WIFI,3G或以太网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发现什么样的网络连接,我连接。它是WiFi或3G?
是有办法做到这一点使用C#赢形式的.NET 2.0或4.0?



 的foreach(在NetworkInterface的适配器适配器)
{
如果(adapter.OperationalStatus == OperationalStatus.Up)
{
如果(adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
{
lblNetworkType.Text =您正在使用WiFi;
中断;
}
,否则如果(adapter.NetworkInterfaceType == NetworkInterfaceType.Ppp)
{
lblNetworkType.Text =您正在使用3G或ADSL或拨号
中断;
}
,否则如果(adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
lblNetworkType.Text =您使用的是以太网;
中断;
}
}
}


解决方案

不幸的是,不是'整洁'的方式来做到这一点本身。 3G连接看起来一样的ADSL或拨号连接(与网络类型为PPP)。



如果你确信你永远只能是在WiFi / 3G,那么你可以检查通过的的NetworkInterface 类的信息=http://msdn.microsoft.com/en-us/library/system .net.networkinformation.networkinterface.getallnetworkinterfaces.aspx相对=nofollow> GetAllNetworkInterfaces ,并把它作为3G如果接口类型为PPP。但正如我所说,这是其他类型的调制解调器连接的相同



编辑:你可能有一些运气寻找3G,HSPA,HSDPA 加密狗,在设备名称或说明。但this'd只能是一个体面的猜测而不是绝对肯定的。


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;
                }
            }
        }

解决方案

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.

这篇关于有没有一种方法来检测我使用的是什么类型的连接? WIFI,3G或以太网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆