June 29, 2009

Measure TCP Throughput using netcat (nc)

netcat (nc) is installed on almost all Linux computers. So when you do not have tools such as iperf available for TCP throughput testing, try the way of doing it with netcat.

On machine A, do :

nc -v -v -l -n -p 2222 >/dev/null

For redhat or Fedora Core do this instead:

nc -v -v -l -n 2222 >/dev/null

On machine B do:
time yes|nc -v -v -n 192.168.0.8 2222 >/dev/null

Now wait 30 seconds, and hit Ctrl-C on machine B, and you shoud get something like this:
sent 87478272, rcvd 0
real 0m9.993s
user 0m2.075s
sys 0m0.939s

Now calculate the throughput
87478272 * 8 / 9.993 (the nubmer above after real)

You can use python as a calculator to do this. :-)

Now that's pretty easy, isn't it?

No comments:

Post a Comment