1.\" $OpenBSD: nc.1,v 1.11 2000/09/26 01:41:44 ericj Exp $ 2.\" 3.\" Copyright (c) 1996 David Sacerdote 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. The name of the author may not be used to endorse or promote products 15.\" derived from this software without specific prior written permission 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27.\" 28.Dd August 1, 1996 29.Dt NC 1 30.Os 31.Sh NAME 32.Nm nc 33.Nd "arbitrary TCP and UDP connections and listens" 34.Sh SYNOPSIS 35.Nm nc 36.Op Fl lnrtuvz 37.Op Fl e Ar command 38.Op Fl g Ar intermediates 39.Op Fl G Ar hopcount 40.Op Fl i Ar interval 41.Op Fl o Ar filename 42.Op Fl p Ar source port 43.Op Fl s Ar ip address 44.Op Fl w Ar timeout 45.Op Ar hostname 46.Op Ar port[s...] 47.Sh DESCRIPTION 48The 49.Nm 50(or 51.Nm netcat ) 52utility is used for just about anything under the sun 53involving TCP or UDP. 54It can open TCP connections, send UDP packets, 55listen on arbitrary TCP and UDP ports, do port scanning, and source 56routing. 57Unlike 58.Xr telnet 1 , 59.Nm 60scripts nicely, and separates error messages onto standard error instead 61of sending them to standard output, as 62.Xr telnet 1 63does with some. 64.Pp 65Destination ports can be single integers, names as listed in 66.Xr services 5 , 67or ranges. 68Ranges are in the form nn-mm, and several separate ports and/or 69ranges may be specified on the command line. 70.Pp 71Common uses include: 72.Pp 73.Bl -bullet -offset indent -compact 74.It 75simple TCP proxies 76.It 77shell\-script based HTTP clients and servers 78.It 79network daemon testing 80.It 81source routing based connectivity testing 82.It 83and much, much more 84.El 85.Pp 86The options are as follows: 87.Bl -tag -width Ds 88.It Fl g Ar intermediate-host 89Specifies a hop along a loose source routed path. 90Can be used more than once to build a chain of hop points. 91.It Fl G Ar pointer 92Positions the 93.Dq hop counter 94within the list of machines in the path of a source routed packet. 95Must be a multiple of 4. 96.It Fl i Ar seconds 97Specifies a delay time interval between lines of text sent and received. 98Also causes a delay time between connections to multiple ports. 99.It Fl l 100Is used to specify that 101.Nm 102should listen for an incoming connection, rather than initiate a 103connection to a remote host. 104Any hostname/IP address and port arguments 105restrict the source of inbound connections to only that address and 106source port. 107.It Fl n 108Do not do DNS lookups on any of the specified addresses or hostnames, or 109names of port numbers from /etc/services. 110.It Fl o Ar filename 111Create a hexadecimal log of data transferred in the specified file. 112Each line begins with 113.Ql < 114or 115.Ql > . 116.Ql < 117means 118.Dq from the net 119and 120.Ql > 121means 122.Dq to the net . 123.It Fl p Ar port 124Specifies the source port 125.Nm 126should use, subject to privilege restrictions and availability. 127.It Fl r 128Specifies that source and/or destination ports should be chosen semi-randomly 129instead of sequentially within a range or in the order that the 130system assigns. 131.It Fl s Ar hostname/ip-address 132Specifies the IP of the interface which is used to send the packets. 133On some platforms, this can be used for UDP spoofing by using 134.Xr ifconfig 8 135to bring up a dummy interface with the desired source IP address. 136.It Fl t 137Causes 138.Nm 139to send RFC854 DON'T and WON'T responses to RFC854 DO 140and WILL requests. 141This makes it possible to use 142.Nm 143to script telnet sessions. 144The presence of this option can be 145enabled or disabled as a compile-time option. 146.It Fl u 147Use UDP instead of TCP. 148On most platforms, 149.Nm 150will behave as if a connection is established until it receives an 151ICMP packet indicating that there is no program listening to what it 152sends. 153.It Fl v 154Verbose. 155Cause 156.Nm 157to display connection information. 158Using 159.Fl v 160more than once will cause 161.Nm 162to become even more verbose. 163.It Fl w Ar timeout 164Specifies the number of seconds 165.Nm 166should wait before deciding that 167an attempt to establish a connection is hopeless. 168Also used to specify how long to wait for more network data after standard 169input closes. 170.It Fl z 171Specifies that 172.Nm 173should just scan for listening 174daemons, without sending any data to them. 175Diagnostic messages about refused connections will not be displayed unless 176.Fl v 177is specified twice. 178.El 179.Sh EXAMPLES 180.Bl -tag -width x 181.It Li "nc" 182Wait for the user to type what would normally be command-line 183arguments on stdin. 184.It Li "nc example.host 42" 185Open a TCP connection to port 42 of example.host. 186If the connection 187fails, do not display any error messages, but simply exit. 188.It Li "nc -p 31337 example.host 42" 189Open a TCP connection to port 42 of example.host, and use port 31337 190as the source port. 191.It Li "nc -w 5 example.host 42" 192Open a TCP connection to port 42 of example.host, and time out after 193five seconds while attempting to connect. 194.It Li "nc -u example.host 53" 195Send any data from stdin 196to UDP port 53 of example.host, and display any data returned. 197.It Li "nc -s 10.1.2.3 example.host 42" 198Open a TCP connection to port 42 of example.host using 10.1.2.3 as the 199IP for the local end of the connection. 200.It Li "nc -v example.host 42" 201Open a TCP connection to port 42 of example.host, displaying some 202diagnostic messages on stderr. 203.It Li "nc -v -v example.host 42" 204Open a TCP connection to port 42 of example.host, displaying all 205diagnostic messages on stderr. 206.It Li "nc -v -z example.host 20-30" 207Attempt to open TCP connections to ports 20 through 30 of 208example.host, and report which ones 209.Nm 210was able to connect to. 211.It Li "nc -v -u -z -w 3 example.host 20-30" 212Send UDP packets to ports 20-30 of example.host, and report which ones 213did not respond with an ICMP packet after three seconds. 214.It Li "nc -l -p 3000" 215Listen on TCP port 3000, and once there is a connection, send stdin to 216the remote host, and send data from the remote host to stdout. 217.It Li "echo foobar | nc example.host 1000" 218Connect to port 1000 of example.host, send the string "foobar" 219followed by a newline, and move data from port 1000 of example.host to 220stdout until example.host closes the connection. 221.El 222.Sh SEE ALSO 223.Xr cat 1 , 224.Xr telnet 1 225.Pp 226The 227.Nm netcat 228.Pa README . 229.Sh AUTHOR 230*Hobbit* [hobbit@avian.org] 231