The nc (or netcat) utility is used for just about anything under the sun involving TCP, UDP, or UNIX-domain sockets. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. Unlike telnet(1), ncscripts nicely, and separates error messages onto standard error instead of sending them to standard output, as telnet(1) does with some.

Common usages

  • nc -l 1234
    • Puts ‘nc’ in listening mode, waiting for incoming connections.
  • nc -l -p 1234
    • Specifies the source port ‘nc’ should use, subject to privilege restrictions and availability.
  • nc -s 192.168.1.5 -l -p 1234
    • Specifies the IP of the network interface which ‘nc’ should use.
  • nc -u localhost 1234
    • Forces ‘nc’ to use UDP instead of the default TCP.
  • nc -v -l -p 1234
    • Makes ‘nc’ give more verbose output.
  • nc -n -l -p 1234
    • Skips DNS name resolution.
  • nc -z localhost 20-30
    • Makes ‘nc’ scan for listening daemons, without sending any data.
  • nc -w 5 localhost 1234
  • nc -w 5 -l -p 1234
    • Sets the timeout for connections and responses.
  • nc -C -l -p 1234
    • Sends CRLF as line-ending.
  • nc -q 5 -l -p 1234
    • After EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever.
Categories: BashServer

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.