netcat

Read and write raw TCP or UDP connections

About

netcat opens raw TCP or UDP connections and pipes data through them. It can also listen for an incoming connection. Use it to test a port, talk to a service by hand, or move one file between machines you control.

Install it

pkg install netcat-openbsd

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

5 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

nc -zv example.com 22 Test whether a single TCP port is open, without sending real data. A lightweight check on a host you manage.
nc -lvnp 4444 Listen on port 4444 for one arriving connection. Handy for moving a file between your own machines.
nc -w 3 example.com 80 Open a raw session to a web port. Type a request by hand and read the reply.
nc -u -l 5353 Listen over UDP instead of TCP. Useful for debugging DNS and other datagram services.
nc -zv -w 2 example.com 20-25 Sweep a small range of ports. A cheap pre-check before a deeper scan.

Worked example

Run nc -zv -w 2 example.com 20-25 and this is what you should see.

termux
$ nc -zv -w 2 example.com 20-25
Connection to example.com 20 port [tcp/ftp-data] succeeded!
Connection to example.com 21 port [tcp/ftp] succeeded!
Connection to example.com 22 port [tcp/ssh] succeeded!
Connection to example.com 23 port [tcp/telnet] refused

Developed by

The OpenBSD project .