windows 确定网络连接链接速度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/849728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Determining the network connection link speed
提问by binarybob
How do I programmatically determine the network connection link speed for an active network connection - like Task Manager shows you in the Networking tab? I'm not really after the bandwidth available, just a figure for the current connection, e.g. 54Mbps, 100Mbps etc.
如何以编程方式确定活动网络连接的网络连接链接速度 - 就像任务管理器在“网络”选项卡中显示一样?我并不是真正追求可用带宽,只是当前连接的一个数字,例如 54Mbps、100Mbps 等。
采纳答案by binarybob
In the end I found the Win32_PerfRawData_Tcpip_NetworkInterface
WMI class, as I need to support legacy platforms which, unfortunately, the Win32_NetworkAdapter
doesn't do. Win32_PerfRawData_Tcpip_NetworkInterface
has a CurrentBandwidth
property which gives me what I need on all required platforms (I realise I said I didn't need "bandwidth" but its acceptable and appears to return the "nominal bandwidth" of the adapter anyway).
最后我找到了Win32_PerfRawData_Tcpip_NetworkInterface
WMI 类,因为我需要支持遗留平台,不幸的是,Win32_NetworkAdapter
它没有这样做。Win32_PerfRawData_Tcpip_NetworkInterface
有一个CurrentBandwidth
属性,它为我提供了所有必需平台上的需求(我意识到我说我不需要“带宽”,但它是可以接受的,并且似乎无论如何都会返回适配器的“标称带宽”)。
Thanks to all those who posted, pointing me in the right direction.
感谢所有发帖的人,为我指明了正确的方向。
回答by Mehrdad Afshari
Win32_NetworkAdapter
WMI class can help you (Speed
property). It returns the value 54000000 for my WiFi adapter connected to a WiFi-g access point.
Win32_NetworkAdapter
WMI 类可以帮助您(Speed
属性)。对于连接到 WiFi-g 接入点的 WiFi 适配器,它返回值 54000000。
回答by Vadym Stetsiak
.NET way how to know adapter speed is
.NET 方式如何知道适配器速度是
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
if ( nics != null )
for (int i = 0; i < nics.Length; i++)
Console.WriteLine("Adapter '{0}' speed : {1}", nics[i].Name, nics[i].Speed);
Some adapters are tunnels, so their speed will be returned as 0. Read NetworkInterfacedocumentation on the MSDN for more information.
某些适配器是隧道,因此它们的速度将返回为 0。有关详细信息,请阅读MSDN 上的NetworkInterface文档。