tags:

views:

235

answers:

3

Using C# what is the most reliable way to calculate network bandwidth speed?

I've found a few examples using NetworkInterface, Performance Counters, native Win32 code, etc. but they all provide different results and none seem to match what other, already existing, tools are showing.

Any advice on the most reliable method to calculate network bandwidth speed in C#?

Edit: To clarify I'm looking to know how much bandwidth a specific interface is currently consuming.

+1  A: 

Using C# what is the most reliable way to calculate network bandwidth speed?

The most realistic way would be to periodically send/download some small test file to/from a knowingly very fast server and notice the time it takes.

Developer Art
To clarify I'm looking to know how much bandwidth a specific interface is currently consuming.
SB
+2  A: 

Same Question:

Try using the System.Net.NetworkInformation classes. In particular, System.Net.NetworkInformation.IPv4InterfaceStatistics ought to have some information along the lines of what you're looking for.

Specifically, you can check the bytesReceived property, wait a given interval, and then check the bytesReceived property again to get an idea of how many bytes/second your connection is processing. To get a good number, though, you should try to download a large block of information from a given source, and check then; that way you should be 'maxing' the connection when you do the test, which should give more helpful numbers

NebuSoft
Thanks, that's one of the methods I'm currently using. My concern is that I get different values using it as opposed to other methods and so I'm not sure which to trust.
SB
+1  A: 

Another way of doing this - albeit it may appear to be cheating as such - create a hidden process using 'netstat -e X' where X is an interval for example, 'netstat -e 5' with the output stream redirected and monitor the figures under the heading 'Received' and 'Sent'... what do you think?

Hope this helps, Best regards, Tom.

tommieb75
I don't think of this as cheating, it's essentially the same as the answer provided by NebuSoft.
overslacked