Search:

PmWiki

pmwiki.org

edit SideBar

Main / Netcat

-n = no resolution of names
-l = listen
-u = udp (tcp is default)
-v = verbosity
-p = port
-s = source IP (for listen, this is really the local/dest IP)
-C = send CRLF line ending

examples:

nc -vvnul 5100
nc6 -vvnul --no-reuseaddr -s 1.1.1.1 -p 5000
cat filename | nc6 -vn --send-only 1.1.1.1 5000
nc6 -vnl -s 1.1.1.1 -p 5100
(this is a way to specify which interface to listen on, so port can be reused)

nc6 is the newer version of netcat; nc6 specific options

--noreuse-address = socket option for listen mode
--send-only = do not listen for response

Installation

There are two flavors of netcat, plus the more modern netcat6.
apt-get install netcat-traditional
apt-get install netcat-openbsd

nc6 has a compile problem, with the -C option being disabled, and it only works with the openBSD version

Multiple TCP Connections

If you are using open-squirt-close methods from a client using nc as a server, note that a listening netcat will keep those connections open for a while even after you close the socket on the client side. There appears to be a default limit of three lingering connections and you'll hang your client trying to make a fourth.

What you need is the -k option to keep looking for connections after one dies, and depending on how fast you are going you'll need the -w <seconds> option to shorten the time the server waits to finally kill a connection. If you make the timeout short enough, you should be able to keep re-using those three slots indefinitely.

nc -vvnlk -w 10 192.168.1.99 8080


Page last modified on November 15, 2023, at 03:10 PM