Code & computing / QUICK REFERENCE

Ncat (netcat) network diagnostics cheat sheet

Quickly test TCP/UDP connectivity, use loopback listeners, inspect streams and make verified TLS connections with Ncat.

50 entries

Connect to a permitted test service

Check installed Ncat version
ncat --version

Confirm the installed executable is Nmap Ncat before relying on its option names. [1][2]

Show supported options
ncat --help

Local help reflects the installed build and its enabled features. [1][2]

Open a loopback TCP session
ncat 127.0.0.1 8080

Connect to a TCP service already listening on the local machine. [1][2]

Force IPv4
ncat -4 127.0.0.1 8080

Select IPv4 transport for this numeric loopback endpoint. [1][2]

Force IPv6
ncat -6 ::1 8080

Connect to IPv6 loopback when a matching listener exists. [1][2]

Print connection details
ncat -v 127.0.0.1 8080

Report connection information as the TCP session starts. [1][2]

Show more diagnostics
ncat -vv 127.0.0.1 8080

Repeated verbose flags provide additional diagnostic messages. [1][2]

Set connection timeout
ncat -w 3 127.0.0.1 8080

Stop trying a connection after the specified wait interval. [1][2]

Test TCP port without sending
ncat -z -w 3 127.0.0.1 8080

Zero-I/O mode reports whether a local TCP connection succeeds. [1][2]

Verbose port check
ncat -z -v -w 3 127.0.0.1 8080

A quick local listener check with connection-status details. [1][2]

Disable name lookups
ncat -n 127.0.0.1 8080

The numeric address works without DNS resolution. [1][2]

Use UDP mode
ncat -u 127.0.0.1 9001

Sends datagrams rather than opening a TCP stream; no handshake confirms a listener. [1][2]

Client with idle timeout
ncat -i 10 127.0.0.1 8080

Closes a connected session after the chosen period of inactivity. [1][2]

Telnet-protocol negotiation
ncat -t 127.0.0.1 2323

Handles Telnet option negotiation against a permitted local service. [1][2]

Safe loopback listener examples

Start local TCP listener
ncat -l 127.0.0.1 9000

Binds only loopback; a separate local terminal can connect to this port. [1][2]

Keep local listener available
ncat -lk 127.0.0.1 9000

Accepts multiple clients; terminate it when the diagnostic task is complete. [1][2]

Start verbose listener
ncat -lv 127.0.0.1 9000

Displays connection notices while listening on localhost. [1][2]

IPv4 loopback listener
ncat -4 -l 127.0.0.1 9000

Explicitly limits the listening socket to IPv4 loopback. [1][2]

IPv6 loopback listener
ncat -6 -l ::1 9000

Limits a listener to the IPv6 localhost address. [1][2]

UDP loopback listener
ncat -u -l 127.0.0.1 9001

Receives UDP datagrams addressed to the local test socket. [1][2]

Keep UDP listener open
ncat -u -lk 127.0.0.1 9001

Can continue handling local UDP test traffic until stopped. [1][2]

Receive only
ncat --recv-only -l 127.0.0.1 9000

Prevents keyboard input from being transmitted back to the connected client. [1][2]

Send only
ncat --send-only -l 127.0.0.1 9000

The listener writes outgoing data but ignores anything sent by a client. [1][2]

Limit allowed client host
ncat -l --allow 127.0.0.1 127.0.0.1 9000

Restricts inbound connections to the numeric local IPv4 address. [1][2]

Limit concurrent connections
ncat -lk --max-conns 2 127.0.0.1 9000

Caps concurrent loopback clients on a persistent listener. [1][2]

Exit with Ctrl+C
Ctrl+C

Stop an interactive local listener after testing; it otherwise holds the port. [1][2]

Inspect application streams

Send local test text
printf 'hello\n' | ncat --send-only 127.0.0.1 9000

Sends a line to an already running local TCP listener and exits on input EOF. [1][3]

Receive a response
ncat --recv-only 127.0.0.1 9000

View data from the other endpoint without typing into the session. [1][3]

Send HTTP request locally
printf 'GET / HTTP/1.0\r\nHost: localhost\r\n\r\n' | ncat 127.0.0.1 8080

Interrogate a plain HTTP loopback server using correctly terminated request lines. [1][3]

Add CRLF automatically
ncat -C 127.0.0.1 8080

Converts typed line endings into CRLF for text-based protocols. [1][3]

Write session log
ncat -o /tmp/ncat-session.log 127.0.0.1 8080

Records session data locally; logs can include private messages. [1][3]

Hexadecimal session dump
ncat -x /tmp/ncat-hex.log 127.0.0.1 8080

Preserves hexadecimal data for binary-protocol diagnosis. [1][3]

Append to an existing log
ncat -o /tmp/ncat-session.log --append-output 127.0.0.1 8080

Appends instead of replacing the selected session log. [1][3]

Use only outgoing data
printf 'probe\n' | ncat --send-only 127.0.0.1 9000

Avoid waiting for a reply when verifying basic payload receipt. [1][3]

Wait briefly after input EOF
printf 'ping\n' | ncat -q 2 127.0.0.1 9000

Quit after the configured EOF delay while allowing short response time. [1][3]

Don't half-close after EOF
ncat --no-shutdown 127.0.0.1 9000

Keep send-side socket behavior when stdin reaches EOF; protocol-specific. [1][3]

Delay lines sent
ncat -d 1 127.0.0.1 9000

Pause one second between lines where supported; helps slow interactive diagnostics. [1][3]

Observe exit status
ncat -z 127.0.0.1 9000; echo $?

Shell status reflects Ncat's result; zero indicates success of the attempted check. [1][3]

TLS, controls and interpretation

Require verified TLS
ncat --ssl-verify test.example 443

Authenticate the remote certificate and negotiate encryption; use a real trusted service hostname. [1][4][3]

Encrypted without verification
ncat --ssl test.example 443

This encrypts traffic but does NOT verify the peer; do not treat it as authenticated. [1][4][3]

Supply a trusted CA bundle
ncat --ssl-verify --ssl-trustfile ca.pem test.example 443

Custom PEM trust chain must be appropriate for the expected service. [1][4][3]

Set a virtual host via SNI
ncat --ssl-verify --ssl-servername test.example test.example 443

Send explicit SNI for a TLS virtual host while requiring certificate verification. [1][4][3]

Verbose certificate check
ncat -v --ssl-verify test.example 443

More logging helps diagnose handshake and certificate issues. [1][4][3]

Try a SOCKS5 proxy
ncat --proxy proxy.example:1080 --proxy-type socks5 test.example 443

Use only a permitted proxy and destination; transport is plain unless TLS is separately enabled. [1][4][3]

Try an HTTP proxy
ncat --proxy proxy.example:3128 --proxy-type http test.example 443

TCP connection traverses an explicitly configured HTTP proxy. [1][4][3]

Combine proxy and TLS
ncat --proxy proxy.example:3128 --proxy-type http --ssl-verify test.example 443

Encrypt and authenticate destination TLS after proxy negotiation. [1][4][3]

Check TCP versus UDP
TCP connects; UDP sends without handshake

A successful UDP send does not prove any application is receiving. [1][4][3]

Interpret connection refused
Port closed, no listener, or active rejection are possibilities

Check local binding, protocol and service status rather than assuming a firewall. [1][4][3]

Interpret connect timeout
Network policy, routing or unresponsive peer may be involved

Narrow the diagnostic with local loopback checks and documented ports. [1][4][3]

Ncat is not every nc
Check ncat --help before reusing examples with nc

OpenBSD netcat, traditional netcat and Nmap Ncat use different option flags. [1][4][3]

Reserved placement, separate from reference controls. No ad network is active.

Updated Nmap Ncat · current user guide

Sources

  1. Ncat Reference Guide ↗
  2. Ncat basic usage ↗
  3. Ncat other options ↗
  4. Ncat SSL reference ↗