utility is used for just about anything under the sun involving TCP
It can open TCP connections, send UDP packets, listen on arbitrary
TCP and UDP ports, do port scanning, and deal with both IPv4 and
scripts nicely, and separates error messages onto standard error instead
of sending them to standard output, as
does with some.
Destination ports can be single integers or ranges.
Ranges are in the form nn-mm.
Common uses include:
simple TCP proxies
shell-script based HTTP clients and servers
network daemon testing
and much, much more
The options are as follows:
to use IPv4 addresses only.
to use IPv6 addresses only.
Specifies a delay time interval between lines of text sent and received.
Also causes a delay time between connections to multiple ports.
to stay listening for another connection after its current connection
Used to specify that
should listen for an incoming connection rather than initiate a
connection to a remote host.
Do not do any DNS or service lookups on any specified addresses,
hostnames or ports.
Specifies the source port
should use, subject to privilege restrictions and availability.
Specifies that source and/or destination ports should be chosen randomly
instead of sequentially within a range or in the order that the system
-s hostname/ip address
Specifies the IP of the interface which is used to send the packets.
to send RFC854 DON'T and WON'T responses to RFC854 DO and WILL requests.
This makes it possible to use
to script telnet sessions.
Use UDP instead of the default option of TCP.
give more verbose output.
-x proxy address [:port]
should connect to
using a SOCKS proxy at address and port.
If port is not specified, port 1080 is used.
should just scan for listening daemons, without sending any data to them.
Specifies to use Unix Domain Sockets.
should use the specified version of the SOCKS protocol when talking to
a SOCKS proxy.
If version is not specified, SOCKS version 5 is used.
$ netcat hostname 42
Open a TCP connection to port 42 of hostname.
$ netcat -p 31337 hostname 42
Open a TCP connection to port 42 of hostname, and use port 31337 as
the source port.
$ netcat -w 5 hostname 42
Open a TCP connection to port 42 of hostname, and timeout after
five seconds while attempting to connect.
$ netcat -u hostname 53
Open a UDP connection to port 53 of hostname.
$ netcat -s 10.1.2.3 example.host 42
Open a TCP connection to port 42 of example.host using 10.1.2.3 as the
IP for the local end of the connection.
$ netcat -v hostname 42
Open a TCP connection to port 42 of hostname, displaying some
diagnostic messages on stderr.
$ netcat -v -z hostname 20-30
Attempt to open TCP connections to ports 20 through 30 of
hostname, and report which ones
was able to connect to.
$ netcat -v -u -z -w 3 hostname 20-30
Send UDP packets to ports 20-30 of example.host, and report which ones
did not respond with an ICMP packet after three seconds.
$ netcat -l 3000
Listen on TCP port 3000, and once there is a connection, send stdin to
the remote host, and send data from the remote host to stdout.
$ echo foobar | netcat hostname 1000
Connect to port 1000 of hostname, send the string "foobar"
followed by a newline, and move data from port 1000 of hostname to
stdout until hostname closes the connection.