问题
Is there any way in Win32 to programmatically determine the bandwidth of a given network interface without actually transferring any data? I only want to distinguish between different types of interface (e.g. dialup vs DSL vs LAN), so a rough order of magnitude is fine, I don't need to actually measure the bandwidth.
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, e.g. dialup modem or GPRS modem.
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.
I'm most interested in Win32/C++ answers, but any ideas would be gratefully received.
回答1:
You can use InternetGetConnectedState to determine the type of connection (LAN/Modem/etc). 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. As far as your computer would be concerned, though, it's on a full speed lan connection...
回答2:
You could use a WMI query, there are of course Win32 functions calls as well, but this query:
Select * from Win32_PerfFormattedData_Tcpip_NetworkInterface
回答3:
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.
来源:https://stackoverflow.com/questions/849375/determine-network-interface-bandwidth-type-without-transferring-data