The nc command, also known as Netcat, is a versatile networking utility for reading and writing data across network connections using TCP or UDP protocols. It can be used to create various network-related tasks such as debugging, transferring files, port scanning, and running a remote shell.
Basic Syntax
nc [options] [hostname] [port]
Here, hostname specifies the hostname or IP address of the remote machine and port specifies the port number on the remote machine to connect to. If hostname is not specified, nc listens for an incoming connection on the specified port. If port is not specified, it defaults to port 23.
Commonly Used Options
-
-l: This option putsncin listening mode, waiting for an incoming connection. -
-p: This option specifies the local port number to use. -
-u: This option specifies to use UDP instead of TCP. -
-v: This option enables verbose output for debugging purposes. -
-w: This option specifies the timeout period for the connection.
Useful Examples
-
nc example.com 80: This connects to the HTTP server on port 80 of example.com. -
nc -l 1234: This listens on port 1234 for an incoming connection. -
nc -l -p 1234: This listens on port 1234 for an incoming connection and uses that port number. -
nc -u example.com 1234: This connects to the UDP server on port 1234 of example.com. -
nc -v example.com 80: This connects to the HTTP server on port 80 of example.com and enables verbose output. -
nc -w 5 example.com 80: This connects to the HTTP server on port 80 of example.com with a timeout period of 5 seconds.
Leave a Reply