简体   繁体   English

确定网络接口带宽/类型而不传输数据

[英]Determine network interface bandwidth/type without transferring data

Is there any way in Win32 to programmatically determine the bandwidth of a given network interface without actually transferring any data? 有没有办法在Win32中以编程方式确定给定网络接口的带宽而不实际传输任何数据? I only want to distinguish between different types of interface (eg dialup vs DSL vs LAN), so a rough order of magnitude is fine, I don't need to actually measure the bandwidth. 我只想区分不同类型的接口(例如拨号与DSL与LAN),因此粗略的数量级很好,我不需要实际测量带宽。

Background to the problem is that my application is very bandwidth-hungry, and I want to display a warning to the user if they try and run it over a low-bandwidth interface, eg dialup modem or GPRS modem. 问题的背景是我的应用程序非常需要带宽,如果他们尝试通过低带宽接口(例如拨号调制解调器或GPRS调制解调器)运行它,我想向用户显示警告。

I've looked at some other related questions but if possible I'd like to avoid measuring throughput. 我已经看了一些其他相关问题,但如果可能的话,我想避免测量吞吐量。 GPRS modems in particular may have usage caps and I don't want to eat into a user's allowance - I'd rather detect the poor connection some other way and not actually send any data at all. 特别是GPRS调制解调器可能有使用上限,我不想吃掉用户的容差 - 我宁愿以其他方式检测到连接不良而根本不发送任何数据。

I'm most interested in Win32/C++ answers, but any ideas would be gratefully received. 我对Win32 / C ++的答案最感兴趣,但任何想法都会感激不尽。

你可以使用WMI查询,当然还有Win32函数调用,但是这个查询:

Select * from Win32_PerfFormattedData_Tcpip_NetworkInterface

You can use InternetGetConnectedState to determine the type of connection (LAN/Modem/etc). 您可以使用InternetGetConnectedState来确定连接类型(LAN /调制解调器/等)。 This will tell you if they have a somewhat decent (non-modem) connection without bandwidth transfer. 这将告诉您他们是否有一个没有带宽传输的有点(非调制解调器)连接。

Unfortunately, you can't really go much beyond that without connecting and transferring data. 不幸的是,如果没有连接和传输数据,你就无法做到这一点。 There is no way for the system to know the bandwidth limitations outside of it's LAN connection - ie: you could connect to your gateway on a LAN directly, and it may have a crappy connection to the outside world. 系统无法知道其LAN连接之外的带宽限制 - 即:您可以直接连接到LAN上的网关,并且可能与外部世界有蹩脚的连接。 As far as your computer would be concerned, though, it's on a full speed lan connection... 但就您的计算机而言,它是全速LAN连接......

Why not asking the user? 为什么不问用户? He should know. 他应该知道。

Your app could cache the information for the network address and only ask again if the network address has changed. 您的应用可以缓存网络地址的信息,并且只会再次询问网络地址是否已更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM