nc - arbitrary TCP and UDP connections and listens (OpenBSD netcat)
nc [-zvnu] [-w timeout] host port | nc -l [-p] port
Options you will use
-z- just connect, send nothing
-v- say what happened
-w N- give up after N seconds
-l- listen
-u- UDP (and UDP "succeeds" without any reply - be careful)
-p PORT- The source port (with -l on older versions: the port to listen on).
-k- With -l: keep listening after a client disconnects.
-n- Do not resolve names (numeric addresses only).
-N- Shut down the network socket after EOF on stdin.
-q SECONDS- After EOF on stdin, wait SECONDS and quit.
-4- IPv4 only.
-6- IPv6 only.
Examples
$ nc -zv db.lab 5432refused, timed out or succeeded
$ nc -zv -w 3 10.0.3.12 5432do not wait two minutes for the kernel
Gotchas
- Refused comes back instantly (RST). A timeout means nothing answered at all - a DROP somewhere.
Taught in
Try nc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.