views:

143

answers:

6

I want to create a bandwidth meter for Windows using vb.net, but I cannot seem to find anything in the .net framework for monitoring the amount of data in or out. I want to create this because I cannot find a good one for free, and I think it is something that people might want.

If there is nothing in the .net framework for monitoring this, is there some P/Invoke calls I can make? If so, what are they?

Is this project feasible? I want to try and measure the exact amount of data in and out, from ALL programs and connections if possible.

Thank you for the help!

EDIT: To clarify, while I doubt that there will be something simple like My.Computer.Network.IO or something like that, I don't really want to make this too complex.

EDIT AGAIN: Perhaps this would be too complicated. If I simply wanted to monitor http activity on port 80, how could I do this without actually disturbing the data?

+1  A: 

You need to go down to driver level and monitor your ethernet device and count up the bytes coming and out.

It'll involve P/Invoke I'm pretty sure. Don't think it's that simple...

Tony
I figured as much. Any way to do this simply without drivers? Then we get into windows logo issues with the warning upon installation, then nobody wants to use your program.
Cyclone
+1  A: 

Some possibilities:

  • WinPCap - Will not give you application, however
  • LSP - Loaded as a DLL into any process that uses Winsock. Gives you everyhting you would want to monitor traffic per-application, but is not simple to write.
  • WMI - Aggregate totals per network interface: http://msdn.microsoft.com/en-us/library/aa394293(VS.85).aspx
Dark Falcon
Hmm, is there any way to simply monitor even a browser for bandwidth? This sounds like far too much work for such a small result
Cyclone
+1  A: 

You could cheat this easily:

  1. Create a process using cmd.exe
  2. Call the command `netstat -e 10' (for 10 seconds)
  3. Pipe the output back to your application as an input stream
  4. Parse the input stream
  5. If the user decides to quit the program send a ctrl-c break sequence to the process.

What do you think?

Hope this helps, Best regards, Tom.

tommieb75
Do you have some tips on how to do this? That looks good!
Cyclone
@Cyclone: Have a look here on how to retrieve console outputs http://www.codeproject.com/KB/threads/CaptureConsole.aspx, That would be your best bet in obtaining the number of bytes in/out by simple regex parsing. :)
tommieb75
@Cyclone: Just to follow up, did the above help you especially the link to codeproject's article?
tommieb75
+1  A: 

Here's a couple of possibilities:

+1  A: 

Your best bet is to use performance counters or WMI and do sampling at a frequency that is comfortable for you. IF you are trying to get something similar to the byte counts on the network card properties those counters are in the performance counter set.

If you are trying to also measure all devices (USB, etc) you will probably need to write your own customer drivers to intercept data transfer events.

GrayWizardx
+1  A: 

There are several performance counters that give you basic numbers on throughput on the network interface card. Start by taking a look at them with Perfmon.exe, you'll see their category, name and instance name. Those same numbers are available with the .NET PerformanceCounter class.

Using them to measure bandwidth is a rather tricky, you are more likely to measure the bandwidth of the server you are talking to, combined with the dozen or so routers that pipe the IP message to your machine.

Hans Passant