nc [-46DCdhklnrtUuvz] [-b if]⌘ [-s source_ip_address][-p source_port]
[-i interval] [-w timeout]
[-X proxy_protocol] [-x proxy_address[:port]]
[host] [port[s]]
open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6.
scripts nicely, and separates error messages to standard error
-l |
host |
> nc -u -v dalogger.dyndns.org 514
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif (null)
src 192.168.1.10 port 52278
dst 74.105.211.198 port 514
rank info not available
Connection to dalogger.dyndns.org port 514 [udp/syslog] succeeded!
<8>testing from nc
produces 2017-01-17T17:07:44.534168-05:00 testing from ncdapie doesn't seem to recognize the timestamp (he adds his own) and a null message creates entry with rtr as host!
< facility*8+level> doesn't seem to be required but is used for destination file
$ nc -l 1234On a second console (or a second machine), connect to the machine and port being listened on:
$ nc 127.0.0.1 1234There is now a connection between the ports, anything typed at the second console will be concatenated to the first, and vice- versa. After the connection has been set up there is no concept of `server' or `client'. The connection is terminated with an EOF (`^D').
$ nc -l 1234 > filename.outUsing a second machine, connect to the listening nc process, feeding it the file which is to be transferred:
$ nc host.example.com 1234 < filename.inAfter the file has been transferred, the connection will close automatically.
$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80This displays the headers sent by the web server. They can be filtered, using sed(1).
More complicated examples can be built up when the user knows the format of requests required by the server. As another example, an email may be submitted to an SMTP server using:
$ nc localhost 25 << EOF
HELO host.example.com
MAIL FROM:
RCPT TO:
DATA
Body of email.
.
QUIT
EOF
$ nc -z host.example.com 20-30
Connection to host.example.com 22 port [tcp/ssh] succeeded!
Connection to host.example.com 25 port [tcp/smtp] succeeded!
The port range was specified to limit the search to ports 20 - 30.
Alternatively, it might be useful to know which server software is running, and which versions. This information is often contained
within the greeting banners. In order to retrieve these, it is necessary to first make a connection, and then break the connection when
the banner has been retrieved. This can be accomplished by specifying a small timeout with the -w flag, or perhaps by issuing a "QUIT"
command to the server:
$ echo "QUIT" | nc host.example.com 20-30
SSH-1.99-OpenSSH_3.6.1p2
Protocol mismatch.
220 host.example.com IMS SMTP Receiver Version 0.84 Ready
$ nc -p 31337 -w 5 host.example.com 42Open a UDP connection to port 53 of host.example.com:
$ nc -u host.example.com 53Open a TCP connection to port 42 of host.example.com using 10.1.2.3 as the IP for the local end of the connection:
$ nc -s 10.1.2.3 host.example.com 42Create and listen on a Unix Domain Socket:
$ nc -lU /var/tmp/dsocketConnect to port 42 of host.example.com via an HTTP proxy at 10.2.3.4, port 8080. This example could also be used by ssh(1); see the ProxyCommand directive in ssh_config(5) for more information.
$ nc -x10.2.3.4:8080 -Xconnect host.example.com 42