← All 165 books netcat, one connection per page
One connection per page

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.


Steve Hodgkiss 7 lessons

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

Contents


Part 1 · The honest pipe
The law first4
Part 2 · One connection
Two hats, one box5
Part 3 · Moving bytes
The -z check6
Part 4 · The dials
Half-close -N7
Part 5 · Speaking by hand
Keep serving -k8
Part 6 · The sharp edges
Not SSH9
Part 7 · The long view
Teaching a friend10

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.

Netcat companion · No. 01
the law

The law first

connect only where welcome

the law before the first byte: whose machine is itport connection attempts arefrequently monitored and loggedthis book's law: connect onlywhere you own or are allowedport scanning, per the Portarticle: cracking attempts oradministrators, never neutral;the owner's answer settles it;if not you and not a yes,the connection does not openevery capture in this book spoke to this machine's own loopback

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.

ONE HONEST CONNECTION

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.

Netcat companion · No. 02
two hats

Two hats, one box

both ends on one machine

two hats, one box: both ends on one machinenc -l 18471the listen hatnc -N 127.0.0.118471nc does not care which side isthe server and which is the clientloopback lets one machine play both ends of one pipe

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.

ONE HONEST CONNECTION

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.

Netcat companion · No. 03
the probe

The -z check

zero-I/O, one honest probe

the -z probe: two doors, two honest answers-zzero-I/O mode [used for scanning]1847318474succeeded!Connection refusednothing sent, either waya knock on your own doors,not a sweep of a stranger's;and over UDP, -uz alwaysreports success, honestlync -zv 127.0.0.118473-18474zero-I/O: the question is only, is anyone home

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.

ONE HONEST CONNECTION

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.

Netcat companion · No. 04
the goodbye

Half-close -N

EOF ends your half, cleanly

the clean goodbye: EOF ends your half of the pipe-Nshutdown the socket afterEOF on stdin-qquit after EOF plus a delayof seconds; implies -Nyour half closes; theirsmay still sendwrite sideread side still opencapture: the listener exitedby itself after the -N sendsome servers require this to finish their work, per the man page

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.

ONE HONEST CONNECTION

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.

Netcat companion · No. 05
the doorman

Keep serving -k

one door, many connections

the doorman: -k listens again after each connection-kkeep inbound sockets openfor multiple connectsnc -k -l 1848112connect oneconnect two, door still open18481 succeeded!, twicestill one connectionat a time; -k changesthe door's patience,never the pipe's shape;-k requires -lserve many friends, one honest connection each

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.

ONE HONEST CONNECTION

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.

Netcat companion · No. 06
no lock

Not SSH

no lock on this pipe

no lock on this pipe: what you type is what travelsnc carries plaintext:hello from the connect sidereadable, letter for letterSSH is the locked door:a cryptographic network protocolfor secure login, port 22Telnet sends usernames and passwordsin plaintext; nc inherits that plainnessSSH was born in 1995 after apassword-sniffing attack, per its articlenc moves bytes; ssh guards them: two jobs, named honestly

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.

ONE HONEST CONNECTION

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.

Netcat companion · No. 07
pass it on

Teaching a friend

one honest hour, one friend

pass the pipe on: five lines, one friend, one hour1succeeded! 18478 [tcp/*]2refused, exit 13pong from the listen side4send.txt = recv.txt, same sha256518473 yes, 18474 nothey type; you read aloudeach line ran on thismachine, loopback only;when the learner can saywhy both answers aregood news, the pipe istheirsone honest hour: five lines, read aloud, understood

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.

ONE HONEST CONNECTION

Sit with one friend and teach this book in one sitting; they type the five lines, you read each answer aloud.

Index

Index


Half-close -N7
Keep serving -k8
Not SSH9
Teaching a friend10
The -z check6
The law first4
Two hats, one box5