summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/nc.1
diff options
context:
space:
mode:
authorjmc <>2004-02-20 10:53:10 +0000
committerjmc <>2004-02-20 10:53:10 +0000
commit4a73d4addd0ec09757fb5005622e2104dc7cca8c (patch)
tree889578544606d0cad802554f554c01f1701fd692 /src/usr.bin/nc/nc.1
parente5d8e73a4c867bf770fd53329255c1c50165ed5e (diff)
downloadopenbsd-4a73d4addd0ec09757fb5005622e2104dc7cca8c.tar.gz
openbsd-4a73d4addd0ec09757fb5005622e2104dc7cca8c.tar.bz2
openbsd-4a73d4addd0ec09757fb5005622e2104dc7cca8c.zip
- sort options and SYNOPSIS
- better document which options do/don't work together - add sections showing some possible uses of nc - code (comment) typos - sync usage() and help suggestions/improvements from otto@ ok deraadt@
Diffstat (limited to 'src/usr.bin/nc/nc.1')
-rw-r--r--src/usr.bin/nc/nc.1260
1 files changed, 196 insertions, 64 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1
index 5bf4480433..64a1dbbc8b 100644
--- a/src/usr.bin/nc/nc.1
+++ b/src/usr.bin/nc/nc.1
@@ -1,4 +1,4 @@
1.\" $OpenBSD: nc.1,v 1.27 2004/01/22 13:28:46 markus Exp $ 1.\" $OpenBSD: nc.1,v 1.28 2004/02/20 10:53:10 jmc Exp $
2.\" 2.\"
3.\" Copyright (c) 1996 David Sacerdote 3.\" Copyright (c) 1996 David Sacerdote
4.\" All rights reserved. 4.\" All rights reserved.
@@ -30,18 +30,21 @@
30.Os 30.Os
31.Sh NAME 31.Sh NAME
32.Nm nc 32.Nm nc
33.Nd "arbitrary TCP and UDP connections and listens" 33.Nd arbitrary TCP and UDP connections and listens
34.Sh SYNOPSIS 34.Sh SYNOPSIS
35.Nm nc 35.Nm nc
36.Op Fl 46hklnrtuvzSU 36.Op Fl 46hklnrStUuvz
37.Op Fl i Ar interval 37.Op Fl i Ar interval
38.Op Fl p Ar source port 38.Op Fl p Ar source_port
39.Op Fl s Ar source ip address 39.Op Fl s Ar source_ip_address
40.Op Fl x Ar proxy address Op :port
41.Op Fl w Ar timeout 40.Op Fl w Ar timeout
42.Op Fl X Ar socks version 41.Op Fl X Ar socks_version
42.Oo Xo
43.Fl x Ar proxy_address Ns Oo : Ns
44.Ar port Oc Oc
45.Xc
43.Op Ar hostname 46.Op Ar hostname
44.Op Ar port[s] 47.Op Ar port Ns Bq Ar s
45.Sh DESCRIPTION 48.Sh DESCRIPTION
46The 49The
47.Nm 50.Nm
@@ -69,7 +72,7 @@ Common uses include:
69.It 72.It
70simple TCP proxies 73simple TCP proxies
71.It 74.It
72shell\-script based HTTP clients and servers 75shell-script based HTTP clients and servers
73.It 76.It
74network daemon testing 77network daemon testing
75.It 78.It
@@ -98,24 +101,41 @@ Forces
98.Nm 101.Nm
99to stay listening for another connection after its current connection 102to stay listening for another connection after its current connection
100is completed. 103is completed.
104It is an error to use this option without the
105.Fl l
106option.
101.It Fl l 107.It Fl l
102Used to specify that 108Used to specify that
103.Nm 109.Nm
104should listen for an incoming connection rather than initiate a 110should listen for an incoming connection rather than initiate a
105connection to a remote host. 111connection to a remote host.
112It is an error to use this option in conjunction with the
113.Fl p ,
114.Fl s ,
115or
116.Fl z
117options.
106.It Fl n 118.It Fl n
107Do not do any DNS or service lookups on any specified addresses, 119Do not do any DNS or service lookups on any specified addresses,
108hostnames or ports. 120hostnames or ports.
109.It Fl p Ar port 121.It Fl p Ar source_port
110Specifies the source port 122Specifies the source port
111.Nm 123.Nm
112should use, subject to privilege restrictions and availability. 124should use, subject to privilege restrictions and availability.
125It is an error to use this option in conjunction with the
126.Fl l
127option.
113.It Fl r 128.It Fl r
114Specifies that source and/or destination ports should be chosen randomly 129Specifies that source and/or destination ports should be chosen randomly
115instead of sequentially within a range or in the order that the system 130instead of sequentially within a range or in the order that the system
116assigns them. 131assigns them.
117.It Fl s Ar hostname/ip address 132.It Fl S
133Enables the RFC 2385 TCP MD5 signature option.
134.It Fl s Ar source_ip_address
118Specifies the IP of the interface which is used to send the packets. 135Specifies the IP of the interface which is used to send the packets.
136It is an error to use this option in conjunction with the
137.Fl l
138option.
119.It Fl t 139.It Fl t
120Causes 140Causes
121.Nm 141.Nm
@@ -123,6 +143,8 @@ to send RFC 854 DON'T and WON'T responses to RFC 854 DO and WILL requests.
123This makes it possible to use 143This makes it possible to use
124.Nm 144.Nm
125to script telnet sessions. 145to script telnet sessions.
146.It Fl U
147Specifies to use Unix Domain Sockets.
126.It Fl u 148.It Fl u
127Use UDP instead of the default option of TCP. 149Use UDP instead of the default option of TCP.
128.It Fl v 150.It Fl v
@@ -143,72 +165,182 @@ will listen forever for a connection, with or without the
143.Fl w 165.Fl w
144flag. 166flag.
145The default is no timeout. 167The default is no timeout.
146.It Fl x Ar proxy address Op :port 168.It Fl X Ar socks_version
169Requests that
170.Nm
171should use the specified version of the SOCKS protocol when talking to
172a SOCKS proxy.
173SOCKS versions 4 and 5 are currently supported.
174If the version is not specified, SOCKS version 5 is used.
175.It Xo
176.Fl x Ar proxy_address Ns Oo : Ns
177.Ar port Oc
178.Xc
147Requests that 179Requests that
148.Nm 180.Nm
149should connect to 181should connect to
150.Ar hostname 182.Ar hostname
151using a SOCKS proxy at address and port. 183using a SOCKS proxy at
152If port is not specified, port 1080 is used. 184.Ar proxy_address
185and
186.Ar port .
187If
188.Ar port
189is not specified, port 1080 is used.
153.It Fl z 190.It Fl z
154Specifies that 191Specifies that
155.Nm 192.Nm
156should just scan for listening daemons, without sending any data to them. 193should just scan for listening daemons, without sending any data to them.
157.It Fl S 194It is an error to use this option in conjunction with the
158Enables the RFC 2385 TCP MD5 signature option. 195.Fl l
159.It Fl U 196option.
160Specifies to use Unix Domain Sockets.
161.It Fl X Ar version
162Requests that
163.Nm
164should use the specified version of the SOCKS protocol when talking to
165a SOCKS proxy.
166If version is not specified, SOCKS version 5 is used.
167.El 197.El
198.Sh CLIENT/SERVER MODEL
199It is quite simple to build a very basic client/server model using
200.Nm .
201On one console, start
202.Nm
203listening on a specific port for a connection.
204For example:
205.Pp
206.Dl $ nc -l 1234
207.Pp
208.Nm
209is now listening on port 1234 for a connection.
210On a second console
211.Pq or a second machine ,
212connect to the machine and port being listened on:
213.Pp
214.Dl $ nc 127.0.0.1 1234
215.Pp
216There should now be a connection between the ports.
217Anything typed at the second console will be concatenated to the first,
218and vice-versa.
219After the connection has been set up,
220.Nm
221does not really care which side is being used as a
222.Sq server
223and which side is being used as a
224.Sq client .
225The connection may be terminated using an
226.Dv EOF
227.Pq Sq ^D .
228.Sh DATA TRANSFER
229The example in the previous section can be expanded to build a
230basic data transfer model.
231Any information input into one end of the connection will be output
232to the other end, and input and output can be easily captured in order to
233emulate file transfer.
234.Pp
235Start by using
236.Nm
237to listen on a specific port, with output captured into a file:
238.Pp
239.Dl $ nc -l 1234 \*(Gt filename.out
240.Pp
241Using a second machine, connect to the listening
242.Nm
243process, feeding it the file which is to be transferred:
244.Pp
245.Dl $ nc host.example.com 1234 \*(Lt filename.in
246.Pp
247After the file has been transferred, the connection will close automatically.
248.Sh TALKING TO SERVERS
249It is sometimes useful to talk to servers
250.Dq by hand
251rather than through a user interface.
252It can aid in troubleshooting,
253when it might be necessary to verify what data a server is sending
254in response to commands issued by the client.
255For example, to retrieve the home page of a web site:
256.Pp
257.Dl $ echo \&"GET\&" | nc host.example.com 80
258.Pp
259Note that this also displays the headers sent by the web server.
260They can be filtered, using a tool such as
261.Xr sed 1 ,
262if necessary.
263.Pp
264More complicated examples can be built up when the user knows the format
265of requests required by the server.
266As another example, an email may be submitted to an SMTP server using:
267.Bd -literal -offset indent
268$ nc localhost 25 \*(Lt\*(Lt EOF
269HELO host.example.com
270MAIL FROM: \*(Ltuser@host.example.com\*(Gt
271RCPT TO: \*(Ltuser2@host.example.com\*(Gt
272DATA
273Body of email.
274\&.
275QUIT
276EOF
277.Ed
278.Sh PORT SCANNING
279It may be useful to know which ports are open and running services on
280a target machine.
281The
282.Fl z
283flag can be used to tell
284.Nm
285not to initiate a connection,
286together with the
287.Fl v
288.Pq verbose
289flag,
290to report open ports.
291For example:
292.Bd -literal -offset indent
293$ nc -vz host.example.com 20-30
294Connection to host.example.com 22 port [tcp/ssh] succeeded!
295Connection to host.example.com 25 port [tcp/smtp] succeeded!
296.Ed
297.Pp
298The port range was specified to limit the search to ports 20 \- 30.
299.Pp
300Alternatively, it might be useful to know which server software
301is running, and which versions.
302This information is often contained within the greeting banners.
303In order to retrieve these, it is necessary to first make a connection,
304and then break the connection when the banner has been retrieved.
305This can be accomplished by specifying a small timeout with the
306.Fl w
307flag, or perhaps by issuing a
308.Qq Dv QUIT
309command to the server:
310.Bd -literal -offset indent
311$ echo "QUIT" | nc host.example.com 20-30
312SSH-1.99-OpenSSH_3.6.1p2
313Protocol mismatch.
314220 host.example.com IMS SMTP Receiver Version 0.84 Ready
315.Ed
168.Sh EXAMPLES 316.Sh EXAMPLES
169.Bl -tag -width x 317Open a TCP connection to port 42 of hostname, using port 31337 as
170.It Li "$ nc hostname 42" 318the source port, with a timeout of 5 seconds:
171Open a TCP connection to port 42 of hostname. 319.Pp
172.It Li "$ nc -p 31337 hostname 42" 320.Dl $ nc -p 31337 -w 5 hostname 42
173Open a TCP connection to port 42 of hostname, and use port 31337 as 321.Pp
174the source port. 322Open a UDP connection to port 53 of hostname:
175.It Li "$ nc -w 5 hostname 42" 323.Pp
176Open a TCP connection to port 42 of hostname, and timeout after 324.Dl $ nc -u hostname 53
177five seconds while attempting to connect. 325.Pp
178.It Li "$ nc -u hostname 53"
179Open a UDP connection to port 53 of hostname.
180.It Li "$ nc -s 10.1.2.3 example.host 42"
181Open a TCP connection to port 42 of example.host using 10.1.2.3 as the 326Open a TCP connection to port 42 of example.host using 10.1.2.3 as the
182IP for the local end of the connection. 327IP for the local end of the connection:
183.It Li "$ nc -v hostname 42" 328.Pp
184Open a TCP connection to port 42 of hostname, displaying some 329.Dl $ nc -s 10.1.2.3 example.host 42
185diagnostic messages on stderr. 330.Pp
186.It Li "$ nc -v -z hostname 20-30"
187Attempt to open TCP connections to ports 20 through 30 of
188hostname, and report which ones
189.Nm
190was able to connect to.
191.It Li "$ nc -v -u -z -w 3 hostname 20-30"
192Send UDP packets to ports 20-30 of example.host, and report which ones 331Send UDP packets to ports 20-30 of example.host, and report which ones
193did not respond with an ICMP packet after three seconds. 332responded with an ICMP packet after three seconds:
194.It Li "$ nc -l 3000" 333.Pp
195Listen on TCP port 3000, and once there is a connection, send stdin to 334.Dl $ nc -uvz -w 3 hostname 20-30
196the remote host, and send data from the remote host to stdout. 335.Pp
197.It Li "$ echo foobar | nc hostname 1000" 336Create and listen on a Unix Domain Socket:
198Connect to port 1000 of hostname, send the string "foobar" 337.Pp
199followed by a newline, and move data from port 1000 of hostname to 338.Dl $ nc -lU /var/tmp/dsocket
200stdout until hostname closes the connection.
201.It Li "$ nc -U /var/tmp/dsocket"
202Connect to a Unix Domain Socket.
203.It Li "$ nc -lU /var/tmp/dsocket"
204Create and listen on a Unix Domain Socket.
205.El
206.Sh SEE ALSO 339.Sh SEE ALSO
207.Xr cat 1 , 340.Xr cat 1
208.Xr telnet 1
209.Sh AUTHORS 341.Sh AUTHORS
210Original implementation by *Hobbit* 342Original implementation by *Hobbit*
211.Aq hobbit@avian.org . 343.Aq hobbit@avian.org .
212.Pp 344.br
213Rewritten with IPv6 support by Eric Jackson 345Rewritten with IPv6 support by
214.Aq ericj@monkey.org . 346.An Eric Jackson Aq ericj@monkey.org .