NC(1)

NAME
nc - arbitrary TCP and UDP connections and listens

SYNOPSIS
nc [-46EhklnrtuvzU] [-e IPsec policy] [-i interval] [-p source port] [-s source ip address] [-x proxy address [:port]] [-w timeout] [hostname] [port[s]]

DESCRIPTION
The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. 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), nc scripts nicely, and separates error messages onto standard error instead of sending them to standard output, as telnet(1), 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:

-4  Forces nc to use IPv4 addresses only.

-6  Forces nc to use IPv6 addresses only.

-h  Prints out nc help.

-E  Shortcut for "-e 'in ipsec esp/transport//require' -e 'out ipsec esp/transport//require'", which enables IPsec ESP transport mode in both directions.

-e  If IPsec support is available, then one can specify the IPsec policies to be used using the syntax described in ipsec_set_policy(3). This flag can be specified up to two times, as typically one policy for each direction is needed.

-i interval
    Specifies a delay time interval between lines of text sent and received. Also causes a delay time between connections to multiple ports.

-k  Forces nc to stay listening for another connection after its current connection is completed.

-l  Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host.

-n  Do not do any DNS or service lookups on any specified addresses, hostnames or ports.

-p port
    Specifies the source port nc should use, subject to privilege restrictions and availability.

-r  Specifies that source and/or destination ports should be chosen randomly instead of sequentially within a range or in the order that the system assigns them.

-s hostname/ip address
    Specifies the IP of the interface which is used to send the packets.

-t  Causes nc to send RFC854 DON'T and WON'T responses to RFC854 DO and WILL requests. This makes it possible to use nc to script telnet sessions.

-u  Use UDP instead of the default option of TCP.

-v  Have nc give more verbose output.

-x proxy address [:port]
    Requests that nc should connect to hostname using a socks5 proxy at address and port. If port is not specified, port 1080 is used.

-z  Specifies that nc should just scan for listening daemons, without sending any data to them.

-U  Specifies to use Unix Domain Sockets.

EXAMPLES

nc hostname 42
    Open a TCP connection to port 42 of hostname.

nc -p 31337 hostname 42
    Open a TCP connection to port 42 of hostname, and use port 31337 as the source port.

nc -w 5 hostname 42
    Open a TCP connection to port 42 of hostname, and timeout after five seconds while attempting to connect.

nc -u hostname 53
    Open a UDP connection to port 53 of hostname.

nc -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.

nc -E example.host 42
    Open a TCP connection to port 42 of example.host using IPsec ESP for incoming and outgoing traffic.

nc -e 'out ipsec esp/transport//require' example.host 42
    Open a TCP connection to port 42 of example.host using IPsec ESP for outgoing traffic only.

nc -v hostname 42
    Open a TCP connection to port 42 of hostname, displaying some diagnostic messages on stderr.

nc -v -z hostname 20-30
    Attempt to open TCP connections to ports 20 through 30 of hostname, and report which ones nc was able to connect to.

nc -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.

nc -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 | nc 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.

nc -U /var/tmp/dsocket
    Connect to a Unix Domain Socket.

nc -lU /var/tmp/dsocket
    Create and listen on a Unix Domain Socket.

SEE ALSO
cat(1), telnet(1)

AUTHORS
Original implementation by *Hobbit* <hobbit@avian.org>.

Rewritten with IPv6 support by Eric Jackson <ericj@monkey.org>.