Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get the instantaneous bandwidth usage of eth0, port 10001. I've looked into using lots of different tools, but most of these seem to have an ncurses type output which isn't suitable for piping into my program.

I've seen How can I get an interface's bandwidth at any given second from the Linux command line?, but this only gives the total statistics over an interface and isn't broken down by port.

Ideally, I'd like a command that takes two arguments (eth0 and port 10001), runs for 500ms, calculates the number and size of packets and outputs a simple megabytes/second metric.

Is this too much to ask?

Anyone got any ideas?

share|improve this question
use tcpdump. feed the file into something that can give you a rate, i think ratesniff or tcptrace can do that – Sirex Feb 29 '12 at 8:45
Actually, I found the answer here:… Works perfectly... – Eamorr Feb 29 '12 at 8:54
You linked your own question here ;p – Journeyman Geek Feb 29 '12 at 10:38
sorry... Here's the correct link:… Many thanks for your help, – Eamorr Feb 29 '12 at 16:36
up vote 1 down vote accepted

You could try to use the ifstat command. With default invocation, it shows bandwidth usage periodically until you hit Control-C But you can invoke it like this:

ifstat <delay> <count>  (i.e. ifstat 1 1)

So that it will give you the bandwidth usage in one second and it's scriptable.

share|improve this answer
So how to specify port with ifstat? – holms Dec 10 '14 at 16:26
@holms it's impossible to specify a port with ifstat, you'll need something else. You may give nethogs a try. – TranslucentCloud Apr 21 '15 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .