How can I see sent/received data by netcat?
I follow this post to check speed with netcat , but in his blog when he do ctrl-c
,he get data on sent received bytes.
In the post he ran :
time yes|nc -v -v -n 192.168.0.8 2222 >/dev/null
than after ctrl-c het get:
sent 87478272, rcvd 0
real 0m9.993s
user 0m2.075s
sys 0m0.939s
When I do ctrl-c
, I don't get this data.
How can I get sent/received data by netcat?
There are actually two implementations of netcat, the original implementation by *Hobbit* (called netcat-traditional
in Debian/Ubuntu) and the OpenBSD implementation (called netcat-openbsd
in Debian/Ubuntu). In Debian/Ubuntu the binaries are called nc.traditional
and nc.openbsd
respectively (and nc
is a link to one of those via the alternatives system).
The blog post you reference is using nc.traditional
which does show the sent/received bytes when exiting. You are probably using nc.openbsd
which doesn't. Install the traditional implementation and call it explicitly.
% time yes | nc.traditional -vvn 127.0.0.1 10000 > /dev/null
(UNKNOWN) [127.0.0.1] 10000 (webmin) open
^C sent 99422208, rcvd 0
yes 1,06s user 0,09s system 38% cpu 3,003 total
Alternately, if you prefer to use the nc.openbsd
you can pipe the output of netcat on the server side to wc -c
and inspect the output like so:
% nc -l -n -p 10000 | wc --bytes
99422208
You can use the Pipe Viewer (pv) utility to watch the visual progress of a stream. It can be modified to display the units of choice and is available on most distributions.
Example:
cat largefile | pv | netcat 192.168.10.1000 1234