Annotation of src/usr.bin/nc/nc.1, Revision 1.11
1.11 ! ericj 1: .\" $OpenBSD: nc.1,v 1.10 2000/07/10 21:52:35 ian Exp $
1.1 deraadt 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
1.3 aaron 29: .Dt NC 1
1.4 deraadt 30: .Os
1.1 deraadt 31: .Sh NAME
32: .Nm nc
1.5 millert 33: .Nd "arbitrary TCP and UDP connections and listens"
1.2 deraadt 34: .Sh SYNOPSIS
1.1 deraadt 35: .Nm nc
1.9 aaron 36: .Op Fl lnrtuvz
1.1 deraadt 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
1.6 aaron 42: .Op Fl p Ar source port
1.1 deraadt 43: .Op Fl s Ar ip address
1.6 aaron 44: .Op Fl w Ar timeout
1.1 deraadt 45: .Op Ar hostname
46: .Op Ar port[s...]
47: .Sh DESCRIPTION
48: The
1.6 aaron 49: .Nm
1.1 deraadt 50: (or
51: .Nm netcat )
52: utility is used for just about anything under the sun
1.7 aaron 53: involving TCP or UDP.
54: It can open TCP connections, send UDP packets,
1.3 aaron 55: listen on arbitrary TCP and UDP ports, do port scanning, and source
1.7 aaron 56: routing.
57: Unlike
1.1 deraadt 58: .Xr telnet 1 ,
1.6 aaron 59: .Nm
1.1 deraadt 60: scripts nicely, and separates error messages onto standard error instead
1.6 aaron 61: of sending them to standard output, as
62: .Xr telnet 1
63: does with some.
1.1 deraadt 64: .Pp
65: Destination ports can be single integers, names as listed in
1.5 millert 66: .Xr services 5 ,
1.7 aaron 67: or ranges.
68: Ranges are in the form nn-mm, and several separate ports and/or
1.1 deraadt 69: ranges may be specified on the command line.
70: .Pp
71: Common uses include:
1.7 aaron 72: .Pp
73: .Bl -bullet -offset indent -compact
1.1 deraadt 74: .It
1.3 aaron 75: simple TCP proxies
1.1 deraadt 76: .It
1.3 aaron 77: shell\-script based HTTP clients and servers
1.1 deraadt 78: .It
79: network daemon testing
80: .It
81: source routing based connectivity testing
82: .It
83: and much, much more
84: .El
85: .Pp
86: The options are as follows:
87: .Bl -tag -width Ds
88: .It Fl g Ar intermediate-host
1.7 aaron 89: Specifies a hop along a loose source routed path.
90: Can be used more than once to build a chain of hop points.
1.1 deraadt 91: .It Fl G Ar pointer
1.7 aaron 92: Positions the
93: .Dq hop counter
94: within the list of machines in the path of a source routed packet.
95: Must be a multiple of 4.
1.1 deraadt 96: .It Fl i Ar seconds
97: Specifies a delay time interval between lines of text sent and received.
98: Also causes a delay time between connections to multiple ports.
99: .It Fl l
100: Is used to specify that
1.6 aaron 101: .Nm
1.1 deraadt 102: should listen for an incoming connection, rather than initiate a
1.7 aaron 103: connection to a remote host.
104: Any hostname/IP address and port arguments
1.1 deraadt 105: restrict the source of inbound connections to only that address and
106: source port.
107: .It Fl n
108: Do not do DNS lookups on any of the specified addresses or hostnames, or
109: names of port numbers from /etc/services.
110: .It Fl o Ar filename
111: Create a hexadecimal log of data transferred in the specified file.
1.7 aaron 112: Each line begins with
113: .Ql <
114: or
115: .Ql > .
116: .Ql <
117: means
118: .Dq from the net
119: and
120: .Ql >
121: means
122: .Dq to the net .
1.1 deraadt 123: .It Fl p Ar port
124: Specifies the source port
1.6 aaron 125: .Nm
1.1 deraadt 126: should use, subject to privilege restrictions and availability.
127: .It Fl r
1.3 aaron 128: Specifies that source and/or destination ports should be chosen semi-randomly
1.1 deraadt 129: instead of sequentially within a range or in the order that the
130: system assigns.
131: .It Fl s Ar hostname/ip-address
1.3 aaron 132: Specifies the IP of the interface which is used to send the packets.
133: On some platforms, this can be used for UDP spoofing by using
134: .Xr ifconfig 8
135: to bring up a dummy interface with the desired source IP address.
1.1 deraadt 136: .It Fl t
137: Causes
1.6 aaron 138: .Nm
1.1 deraadt 139: to send RFC854 DON'T and WON'T responses to RFC854 DO
1.7 aaron 140: and WILL requests.
141: This makes it possible to use
1.6 aaron 142: .Nm
1.7 aaron 143: to script telnet sessions.
144: The presence of this option can be
1.1 deraadt 145: enabled or disabled as a compile-time option.
146: .It Fl u
1.6 aaron 147: Use UDP instead of TCP.
1.1 deraadt 148: On most platforms,
1.6 aaron 149: .Nm
1.1 deraadt 150: will behave as if a connection is established until it receives an
151: ICMP packet indicating that there is no program listening to what it
152: sends.
153: .It Fl v
1.7 aaron 154: Verbose.
155: Cause
1.6 aaron 156: .Nm
1.7 aaron 157: to display connection information.
158: Using
1.3 aaron 159: .Fl v
1.1 deraadt 160: more than once will cause
1.6 aaron 161: .Nm
1.1 deraadt 162: to become even more verbose.
163: .It Fl w Ar timeout
164: Specifies the number of seconds
1.6 aaron 165: .Nm
1.1 deraadt 166: should wait before deciding that
167: an attempt to establish a connection is hopeless.
168: Also used to specify how long to wait for more network data after standard
169: input closes.
170: .It Fl z
171: Specifies that
1.6 aaron 172: .Nm
1.1 deraadt 173: should just scan for listening
1.7 aaron 174: daemons, without sending any data to them.
1.10 ian 175: Diagnostic messages about refused connections will not be displayed unless
1.3 aaron 176: .Fl v
177: is specified twice.
1.8 aaron 178: .El
1.1 deraadt 179: .Sh EXAMPLES
180: .Bl -tag -width x
181: .It Li "nc"
182: Wait for the user to type what would normally be command-line
1.10 ian 183: arguments on stdin.
1.1 deraadt 184: .It Li "nc example.host 42"
1.7 aaron 185: Open a TCP connection to port 42 of example.host.
186: If the connection
1.1 deraadt 187: fails, do not display any error messages, but simply exit.
188: .It Li "nc -p 31337 example.host 42"
189: Open a TCP connection to port 42 of example.host, and use port 31337
190: as the source port.
191: .It Li "nc -w 5 example.host 42"
1.3 aaron 192: Open a TCP connection to port 42 of example.host, and time out after
1.1 deraadt 193: five seconds while attempting to connect.
194: .It Li "nc -u example.host 53"
195: Send any data from stdin
196: to UDP port 53 of example.host, and display any data returned.
197: .It Li "nc -s 10.1.2.3 example.host 42"
1.3 aaron 198: Open a TCP connection to port 42 of example.host using 10.1.2.3 as the
199: IP for the local end of the connection.
1.1 deraadt 200: .It Li "nc -v example.host 42"
1.3 aaron 201: Open a TCP connection to port 42 of example.host, displaying some
1.1 deraadt 202: diagnostic messages on stderr.
203: .It Li "nc -v -v example.host 42"
1.3 aaron 204: Open a TCP connection to port 42 of example.host, displaying all
1.1 deraadt 205: diagnostic messages on stderr.
206: .It Li "nc -v -z example.host 20-30"
1.3 aaron 207: Attempt to open TCP connections to ports 20 through 30 of
1.1 deraadt 208: example.host, and report which ones
1.6 aaron 209: .Nm
1.1 deraadt 210: was able to connect to.
211: .It Li "nc -v -u -z -w 3 example.host 20-30"
1.3 aaron 212: Send UDP packets to ports 20-30 of example.host, and report which ones
1.1 deraadt 213: did not respond with an ICMP packet after three seconds.
214: .It Li "nc -l -p 3000"
215: Listen on TCP port 3000, and once there is a connection, send stdin to
216: the remote host, and send data from the remote host to stdout.
217: .It Li "echo foobar | nc example.host 1000"
218: Connect to port 1000 of example.host, send the string "foobar"
219: followed by a newline, and move data from port 1000 of example.host to
220: stdout until example.host closes the connection.
221: .El
222: .Sh SEE ALSO
223: .Xr cat 1 ,
1.3 aaron 224: .Xr telnet 1
225: .Pp
226: The
1.1 deraadt 227: .Nm netcat
1.3 aaron 228: .Pa README .
1.1 deraadt 229: .Sh AUTHOR
230: *Hobbit* [hobbit@avian.org]