Netcat

From wikinotes
Revision as of 19:31, 12 April 2021 by Will (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

NetCat is a very useul tool for sending/receiving messages over TCP. I use it almost-daily to test daemons, servers, connections, etc. I believe technically it is slowly being replaced by ss, which I still need to read up on.

It's syntax varies slightly from platform to platform, but it's man-page is very comprehensive and helpful.


nc \
  -u  # send udp packets \
  -v  # verbose \
  -z  # check if reachable \
nc -l -p 6001                     # Listen to port 6001 on localhost

echo "hello" | nc 127.0.0.1 6001  # Send test 'hello' to port 6001 on localhost
nc -z domain.com 443   # check errorcode to see if connection was possible