netcat, one connection per page
Twenty-eight lessons on what netcat is: a utility that reads from and writes to network connections over TCP or UDP; nc from Hobbit, announced 1995, version 1.10 in 1996; the law of connecting only where you are welcome; one connection per page: the plain connect, the -l listen, two hats on one machine, ports as 16-bit doors; chat, a file sent one connection at a time, the banner read, the -z zero-I/O check; the -w timeout, UDP with -u, telnet mode -t, the -N half-close; a GET by hand, debugging a listener, -v, keep serving with -k; the -e danger named, no lock on the pipe, the open listener, not a scanner; the variants, the Unix door -U, one keeper command; teaching a friend in one sitting.
One honest connection at a time. That's the whole tool.
netcat, one connection per page
Twenty-eight lessons on what netcat is: a utility that reads from and writes to network connections over TCP or UDP; nc from Hobbit, announced 1995, version 1.10 in 1996; the law of connecting only where you are welcome; one connection per page: the plain connect, the -l listen, two hats on one machine, ports as 16-bit doors; chat, a file sent one connection at a time, the banner read, the -z zero-I/O check; the -w timeout, UDP with -u, telnet mode -t, the -N half-close; a GET by hand, debugging a listener, -v, keep serving with -k; the -e danger named, no lock on the pipe, the open listener, not a scanner; the variants, the Unix door -U, one keeper command; teaching a friend in one sitting.
Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).
Every fact is as the official source states it, fetched and read during this build: the local nc -h help text and nc man page of OpenBSD netcat, Debian patchlevel 1.226-1ubuntu2, on this machine, the truth for flags and behavior, and the Wikipedia articles Netcat, Berkeley sockets, Transmission Control Protocol, User Datagram Protocol, Port (computer networking), Telnet, SSH and List of TCP and UDP port numbers. No facts come from Reddit, Stack Overflow, vendor blogs or commercial sites. Every connection quoted ran against this machine's loopback only (127.0.0.1, or a Unix-domain socket on this machine), cached verbatim beside this book.
Honest notes: no -e exec demo ran, and this OpenBSD nc has no -e option at all, per its own help text; no -t TELNET negotiation demo ran; the -uz UDP caveat is quoted from the man page without a demo. The SSH article was reached via a redirect from the Secure Shell stub, which was not used as a source. SAFETY LAW: no third-party host was ever contacted. Independent, not affiliated with the OpenBSD project, the GNU Project or the Wikimedia Foundation.
Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.
© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.
Edition 1.0 · stevehodgkiss.net
Contents
Per the Wikipedia Port (computer networking) article, the practice of attempting to connect to a range of ports in sequence on a single host is commonly known as port scanning, it is usually associated either with malicious cracking attempts or with network administrators looking for possible vulnerabilities, and port connection attempts are frequently monitored and logged by hosts. Per this book's plan, the law is: open connections only to machines you own or are explicitly allowed to touch, which is why every capture here used loopback only.
The law first
Before the first connection, the law. Per the Port article, connecting to a range of ports in sequence is commonly known as port scanning, associated with cracking attempts or with administrators.
The red edge is real: Port connection attempts are frequently monitored and logged by hosts. An uninvited connection is a record with your address on it.
So this book's law, per this book's plan: open connections only to machines you own or are allowed to touch. Every capture here spoke to 127.0.0.1.
Before your next connection, say whose machine sits at the far end; if not yours, name the yes that allows it.
Per the local nc man page's CLIENT/SERVER MODEL section, on one console start nc listening on a specific port, on a second console connect with nc -N 127.0.0.1 1234, there should now be a connection between the ports, anything typed at the second console will be concatenated to the first, and vice-versa, and after the connection has been set up, nc does not really care which side is being used as a server and which side as a client. This machine's capture: a listener on 18471 fed reply.txt received hello from the connect side while the connect side received pong from the listen side.
Two hats, one box
One machine can wear both hats. Per the man page, start nc -l on one console, nc -N 127.0.0.1 on another, and there should now be a connection between the ports.
Then the symmetry: nc does not really care which side is being used as a server and which side as a client. Once joined, both ends are keyboards and screens on one pipe.
Our capture, both ends loopback: the listener received hello from the connect side; the connect side received pong from the listen side.
Open two terminals and pass one sentence each way; count the connections used: one.
Per the local nc -h help text, -z is Zero-I/O mode [used for scanning]. Per the local nc man page, -z only scans for listening daemons, without sending any data to them, and cannot be used together with -l; the -w flag bounds the wait; and per the man page's CAVEATS, UDP port scans using the -uz combination of flags will always report success. This machine's capture: nc -zv 127.0.0.1 18473-18474 answered succeeded for 18473 where a listener sat and Connection refused for 18474 where none sat, exit status 0.
The -z check
One flag, one question. Per the help text, -z is Zero-I/O mode [used for scanning]; per the man page it asks about listening daemons without sending any data to them, and cannot be used with -l.
Our capture: nc -zv 127.0.0.1 18473-18474: 18473 port [tcp/*] succeeded! where one sat, and 18474 failed: Connection refused where none sat.
Honest edges: a knock, not a sweep; and -uz over UDP will always report success. Ask doors you own.
Probe two of your own ports, one open one closed; read each answer aloud.
Per the local nc -h help text, -N shuts down the network socket after EOF on stdin and -q secs quits after EOF on stdin and a delay of secs. Per the local nc man page, -N shuts down the socket after EOF on the input and some servers require this to finish their work; -q waits the specified number of seconds after EOF then quits, and specifying a non-negative seconds implies -N. This machine's capture: after nc -N 127.0.0.1 18472 finished sending send.txt, the listener exited by itself with no kill needed.
Half-close -N
Ending is part of the craft. Per the help text, -N will Shutdown the network socket after EOF on stdin, and -q secs will quit after EOF on stdin and delay of secs.
Per the man page, some servers require this to finish their work; a non-negative -q even implies -N.
Our capture: the file-send listener exited by itself once the -N sender hit EOF. No kill, no hang: one clean goodbye.
Send with -N once and watch the far end end itself; then say why plain EOF is not always enough.
Per the local nc -h help text, -k keeps inbound sockets open for multiple connects. Per the local nc man page, with -k, when a connection is completed, nc listens for another one; -k requires -l. This machine's capture: against nc -k -l 18481, two sequential connects each answered Connection to 127.0.0.1 18481 port [tcp/*] succeeded!, and the listener was still alive after the first, serving the second over a new connection.
Keep serving -k
By default the listener serves one connection and retires. Per the help text, -k will Keep inbound sockets open for multiple connects; per the man page, when a connection is completed, listen for another one, and -k requires -l.
Our capture: nc -k -l 18481, then two connects in turn; both answered 18481 port [tcp/*] succeeded!, and the listener stayed alive after the first.
Still one connection at a time. -k changes the door's patience, never the pipe's shape.
Serve two connections through one -k listener and count the connections: two, not one long one.
Per the Wikipedia SSH article, SSH is a cryptographic network protocol for operating network services securely over an unsecured network, its most notable applications are remote login and command-line execution, and Tatu Ylönen designed it in 1995 prompted by a password-sniffing attack; the IANA has assigned TCP port 22. Per the Wikipedia Telnet article, Telnet transmits all information including usernames and passwords in plaintext. This machine's capture: the loopback chat's line hello from the connect side arrived readable, letter for letter, at the listener: that is what nc carries, plaintext.
Not SSH
nc has no lock. What you type crosses the wire exactly as written; our chat capture shows the listener reading hello from the connect side letter for letter.
Per the Telnet article, the old remote-login tool transmits all information including usernames and passwords in plaintext; nc inherits that plainness.
For login, use SSH: per its article, a cryptographic network protocol for secure remote login, born in 1995 after a password-sniffing attack, on port 22. nc moves bytes; ssh guards them.
Name the two jobs honestly: which tool moves bytes plainly, and which tool logs in with a lock?
Per this book's plan, the last lesson hands nc to a friend in one honest hour: five captured lines from this book, typed by the learner against listeners the learner owns, read aloud by the teacher. The captures behind the five lines: the plain connect's succeeded line, the refused line with exit 1, the chat's two-way exchange, the file send's matching hashes, and the -z probe's two answers.
Teaching a friend
The last piece is passing the pipe on: one friend, one honest hour, per this book's plan. They type; you read aloud.
Five lines, this book's captures: the connect's succeeded!, the dead port's Connection refused with exit 1, the chat's pong from the listen side, the file send's matching hashes, and the -z probe's two answers.
When they can say why refused and succeeded are both good news, the hour is done and the pipe is theirs.
Sit with one friend and teach this book in one sitting; they type the five lines, you read each answer aloud.