1124 lines
17 KiB
HTML
1124 lines
17 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of NC</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>NC</H1>
|
|
Section: User Commands (1)<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
<BR>BSD mandoc<BR>
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
|
|
|
|
<B>nc</B>
|
|
|
|
- arbitrary TCP and UDP connections and listens
|
|
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>nc</B>
|
|
|
|
[-<B>46bCDdFhklNnrStUuvZz </B>[-<B>I </B><I>length</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>i </B><I>interval</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>M </B><I>ttl</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>m </B><I>minttl</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>O </B><I>length</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>P </B><I>proxy_username</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>p </B><I>source_port</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>q </B><I>seconds</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>s </B><I>source</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>T </B><I>keyword</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>V </B><I>rtable</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>W </B><I>recvlimit</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>w </B><I>timeout</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>X </B><I>proxy_protocol</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>x </B><I>proxy_address </I><B></B>[: <B></B><I>port</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
[<I>destination</I>
|
|
|
|
]
|
|
|
|
[<I>port</I>
|
|
|
|
]
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>nc</B>
|
|
|
|
|
|
(or
|
|
<B>netcat</B>
|
|
|
|
|
|
utility is used for just about anything under the sun involving TCP,
|
|
UDP, or
|
|
UNIX
|
|
sockets.
|
|
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
|
|
<A HREF="/cgi-bin/man/man2html?1+telnet">telnet</A>(1),
|
|
|
|
|
|
<B>nc</B>
|
|
|
|
|
|
scripts nicely, and separates error messages onto standard error instead
|
|
of sending them to standard output, as
|
|
<A HREF="/cgi-bin/man/man2html?1+telnet">telnet</A>(1)
|
|
|
|
|
|
does with some.
|
|
<P>
|
|
|
|
Common uses include:
|
|
<P>
|
|
|
|
<UL><P>
|
|
|
|
<LI>
|
|
|
|
simple TCP proxies
|
|
<LI>
|
|
|
|
shell-script based HTTP clients and servers
|
|
<LI>
|
|
|
|
network daemon testing
|
|
<LI>
|
|
|
|
a SOCKS or HTTP ProxyCommand for
|
|
<A HREF="/cgi-bin/man/man2html?1+ssh">ssh</A>(1)
|
|
|
|
|
|
<LI>
|
|
|
|
and much, much more
|
|
</UL><P>
|
|
|
|
<P>
|
|
|
|
The options are as follows:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="1"><B>-4</B>
|
|
|
|
|
|
<DD>
|
|
Use IPv4 addresses only.
|
|
<DT id="2"><B>-6</B>
|
|
|
|
|
|
<DD>
|
|
Use IPv6 addresses only.
|
|
<DT id="3"><B>-b</B>
|
|
|
|
|
|
<DD>
|
|
Allow broadcast.
|
|
<DT id="4"><B>-C</B>
|
|
|
|
|
|
<DD>
|
|
Send CRLF as line-ending. Each line feed (LF) character from the input
|
|
data is translated into CR+LF before being written to the socket. Line
|
|
feed characters that are already preceded with a carriage return (CR)
|
|
are not translated. Received data is not affected.
|
|
<DT id="5"><B>-D</B>
|
|
|
|
|
|
<DD>
|
|
Enable debugging on the socket.
|
|
<DT id="6"><B>-d</B>
|
|
|
|
|
|
<DD>
|
|
Do not attempt to read from stdin.
|
|
<DT id="7"><B>-F</B>
|
|
|
|
|
|
<DD>
|
|
Pass the first connected socket using
|
|
<A HREF="/cgi-bin/man/man2html?2+sendmsg">sendmsg</A>(2)
|
|
|
|
|
|
to stdout and exit.
|
|
This is useful in conjunction with
|
|
-<B>X</B>
|
|
|
|
to have
|
|
<B>nc</B>
|
|
|
|
|
|
perform connection setup with a proxy but then leave the rest of the
|
|
connection to another program (e.g.
|
|
<A HREF="/cgi-bin/man/man2html?1+ssh">ssh</A>(1)
|
|
|
|
|
|
using the
|
|
ssh_config5
|
|
|
|
|
|
<B>ProxyUseFdpass</B>
|
|
|
|
option).
|
|
Cannot be used with
|
|
-<B>U</B>
|
|
|
|
|
|
<DT id="8"><B>-h</B>
|
|
|
|
|
|
<DD>
|
|
Print out the
|
|
<B>nc</B>
|
|
|
|
|
|
help text and exit.
|
|
<DT id="9"><B>-I </B><I>length</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Specify the size of the TCP receive buffer.
|
|
<DT id="10"><B>-i </B><I>interval</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Sleep for
|
|
<I>interval</I>
|
|
|
|
seconds between lines of text sent and received.
|
|
Also causes a delay time between connections to multiple ports.
|
|
<DT id="11"><B>-k</B>
|
|
|
|
|
|
<DD>
|
|
When a connection is completed, listen for another one.
|
|
Requires
|
|
-<B>l</B>
|
|
|
|
|
|
When used together with the
|
|
-<B>u</B>
|
|
|
|
option, the server socket is not connected and it can receive UDP datagrams from
|
|
multiple hosts.
|
|
<DT id="12"><B>-l</B>
|
|
|
|
|
|
<DD>
|
|
Listen for an incoming connection rather than initiating a
|
|
connection to a remote host.
|
|
The
|
|
<I>destination</I>
|
|
|
|
and
|
|
<I>port</I>
|
|
|
|
to listen on can be specified either as non-optional arguments, or with
|
|
options
|
|
-<B>s</B>
|
|
|
|
and
|
|
-<B>p</B>
|
|
|
|
respectively.
|
|
Cannot be used together with
|
|
-<B>x</B>
|
|
|
|
or
|
|
-<B>z</B>
|
|
|
|
|
|
Additionally, any timeouts specified with the
|
|
-<B>w</B>
|
|
|
|
option are ignored.
|
|
<DT id="13"><B>-M </B><I>ttl</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Set the TTL / hop limit of outgoing packets.
|
|
<DT id="14"><B>-m </B><I>minttl</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Ask the kernel to drop incoming packets whose TTL / hop limit is under
|
|
<I>minttl</I>
|
|
|
|
|
|
<DT id="15"><B>-N</B>
|
|
|
|
|
|
<DD>
|
|
<A HREF="/cgi-bin/man/man2html?2+shutdown">shutdown</A>(2)
|
|
|
|
|
|
the network socket after EOF on the input.
|
|
Some servers require this to finish their work.
|
|
<DT id="16"><B>-n</B>
|
|
|
|
|
|
<DD>
|
|
Do not do any DNS or service lookups on any specified addresses,
|
|
hostnames or ports.
|
|
<DT id="17"><B>-O </B><I>length</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Specify the size of the TCP send buffer.
|
|
<DT id="18"><B>-P </B><I>proxy_username</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Specifies a username to present to a proxy server that requires authentication.
|
|
If no username is specified then authentication will not be attempted.
|
|
Proxy authentication is only supported for HTTP CONNECT proxies at present.
|
|
<DT id="19"><B>-p </B><I>source_port</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Specify the source port
|
|
<B>nc</B>
|
|
|
|
|
|
should use, subject to privilege restrictions and availability.
|
|
<DT id="20"><B>-q </B><I>seconds</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
after EOF on stdin, wait the specified number of
|
|
<I>seconds</I>
|
|
|
|
and then quit. If
|
|
<I>seconds</I>
|
|
|
|
is negative, wait forever (default). Specifying a non-negative
|
|
<I>seconds</I>
|
|
|
|
implies
|
|
-<B>N</B>
|
|
|
|
|
|
<DT id="21"><B>-r</B>
|
|
|
|
|
|
<DD>
|
|
Choose source and/or destination ports randomly
|
|
instead of sequentially within a range or in the order that the system
|
|
assigns them.
|
|
<DT id="22"><B>-S</B>
|
|
|
|
|
|
<DD>
|
|
Enable the RFC 2385 TCP MD5 signature option.
|
|
<DT id="23"><B>-s </B><I>source</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Send packets from the interface with the
|
|
<I>source</I>
|
|
|
|
IP address.
|
|
For
|
|
UNIX
|
|
datagram sockets, specifies the local temporary socket file
|
|
to create and use so that datagrams can be received.
|
|
Cannot be used together with
|
|
-<B>x</B>
|
|
|
|
|
|
<DT id="24"><B>-T </B><I>keyword</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Change the IPv4 TOS/IPv6 traffic class value.
|
|
<I>keyword</I>
|
|
|
|
may be one of
|
|
<B>critical</B>
|
|
|
|
|
|
<B>inetcontrol</B>
|
|
|
|
|
|
<B>lowcost</B>
|
|
|
|
|
|
<B>lowdelay</B>
|
|
|
|
|
|
<B>netcontrol</B>
|
|
|
|
|
|
<B>throughput</B>
|
|
|
|
|
|
<B>reliability</B>
|
|
|
|
|
|
or one of the DiffServ Code Points:
|
|
<B>ef</B>
|
|
|
|
|
|
<B>af11 ... af43</B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<B>cs0 ... cs7</B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
or a number in either hex or decimal.
|
|
<DT id="25"><B>-t</B>
|
|
|
|
|
|
<DD>
|
|
Send RFC 854 DON'T and WON'T responses to RFC 854 DO and WILL requests.
|
|
This makes it possible to use
|
|
<B>nc</B>
|
|
|
|
|
|
to script telnet sessions.
|
|
<DT id="26"><B>-U</B>
|
|
|
|
|
|
<DD>
|
|
Use
|
|
UNIX
|
|
sockets.
|
|
Cannot be used together with
|
|
-<B>F</B>
|
|
|
|
or
|
|
-<B>x</B>
|
|
|
|
|
|
<DT id="27"><B>-u</B>
|
|
|
|
|
|
<DD>
|
|
Use UDP instead of TCP.
|
|
Cannot be used together with
|
|
-<B>x</B>
|
|
|
|
|
|
For
|
|
UNIX
|
|
sockets, use a datagram socket instead of a stream socket.
|
|
If a
|
|
UNIX
|
|
socket is used, a temporary receiving socket is created in
|
|
/tmp
|
|
|
|
unless the
|
|
-<B>s</B>
|
|
|
|
flag is given.
|
|
<DT id="28"><B>-V </B><I>rtable</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Set the routing table to be used.
|
|
<DT id="29"><B>-v</B>
|
|
|
|
|
|
<DD>
|
|
Produce more verbose output.
|
|
<DT id="30"><B>-W </B><I>recvlimit</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Terminate after receiving
|
|
<I>recvlimit</I>
|
|
|
|
packets from the network.
|
|
<DT id="31"><B>-w </B><I>timeout</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Connections which cannot be established or are idle timeout after
|
|
<I>timeout</I>
|
|
|
|
seconds.
|
|
The
|
|
-<B>w</B>
|
|
|
|
flag has no effect on the
|
|
-<B>l</B>
|
|
|
|
option, i.e.
|
|
<B>nc</B>
|
|
|
|
|
|
will listen forever for a connection, with or without the
|
|
-<B>w</B>
|
|
|
|
flag.
|
|
The default is no timeout.
|
|
<DT id="32"><B>-X </B><I>proxy_protocol</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Use
|
|
<I>proxy_protocol</I>
|
|
|
|
when talking to the proxy server.
|
|
Supported protocols are
|
|
<B>4</B>
|
|
|
|
(SOCKS v.4),
|
|
<B>5</B>
|
|
|
|
(SOCKS v.5)
|
|
and
|
|
<B>connect</B>
|
|
|
|
(HTTPS proxy).
|
|
If the protocol is not specified, SOCKS version 5 is used.
|
|
<DT id="33"><B>-x </B><I>proxy_address </I><B></B>[: <B></B><I>port</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Connect to
|
|
<I>destination</I>
|
|
|
|
using a proxy at
|
|
<I>proxy_address</I>
|
|
|
|
and
|
|
<I>port</I>
|
|
|
|
|
|
If
|
|
<I>port</I>
|
|
|
|
is not specified, the well-known port for the proxy protocol is used (1080
|
|
for SOCKS, 3128 for HTTPS).
|
|
An IPv6 address can be specified unambiguously by enclosing
|
|
<I>proxy_address</I>
|
|
|
|
in square brackets.
|
|
A proxy cannot be used with any of the options
|
|
-<B>lsuU</B>
|
|
|
|
|
|
<DT id="34"><B>-Z</B>
|
|
|
|
|
|
<DD>
|
|
DCCP mode.
|
|
<DT id="35"><B>-z</B>
|
|
|
|
|
|
<DD>
|
|
Only scan for listening daemons, without sending any data to them.
|
|
Cannot be used together with
|
|
-<B>l</B>
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
<I>destination</I>
|
|
|
|
can be a numerical IP address or a symbolic hostname
|
|
(unless the
|
|
-<B>n</B>
|
|
|
|
option is given).
|
|
In general, a destination must be specified,
|
|
unless the
|
|
-<B>l</B>
|
|
|
|
option is given
|
|
(in which case the local host is used).
|
|
For
|
|
UNIX
|
|
sockets, a destination is required and is the socket path to connect to
|
|
(or listen on if the
|
|
-<B>l</B>
|
|
|
|
option is given).
|
|
<P>
|
|
|
|
<I>port</I>
|
|
|
|
can be specified as a numeric port number or as a service name.
|
|
Port ranges may be specified as numeric port numbers of the form
|
|
<I>nn </I><B>- </B><I>mm</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In general,
|
|
a destination port must be specified,
|
|
unless the
|
|
-<B>U</B>
|
|
|
|
option is given.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>CLIENT/SERVER MODEL</H2>
|
|
|
|
It is quite simple to build a very basic client/server model using
|
|
<B>.</B>
|
|
|
|
On one console, start
|
|
<B>nc</B>
|
|
|
|
|
|
listening on a specific port for a connection.
|
|
For example:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -l 1234</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
<B>nc</B>
|
|
|
|
|
|
is now listening on port 1234 for a connection.
|
|
On a second console
|
|
(or a second machine)
|
|
|
|
|
|
connect to the machine and port being listened on:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc 127.0.0.1 1234</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
There should now be 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,
|
|
<B>nc</B>
|
|
|
|
|
|
does not really care which side is being used as a
|
|
`server'
|
|
|
|
and which side is being used as a
|
|
`client'
|
|
|
|
|
|
The connection may be terminated using an
|
|
<B>EOF</B>
|
|
|
|
(`^D'
|
|
|
|
)
|
|
|
|
|
|
<P>
|
|
|
|
There is no
|
|
-<B>c</B>
|
|
|
|
or
|
|
-<B>e</B>
|
|
|
|
option in this netcat, but you still can execute a command after connection
|
|
being established by redirecting file descriptors. Be cautious here because
|
|
opening a port and let anyone connected execute arbitrary command on your
|
|
site is DANGEROUS. If you really need to do this, here is an example:
|
|
<P>
|
|
|
|
On
|
|
`server'
|
|
|
|
side:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ rm -f /tmp/f; mkfifo /tmp/f</TT></BLOCKQUOTE>
|
|
|
|
<BLOCKQUOTE><TT>$ cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
On
|
|
`client'
|
|
|
|
side:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc host.example.com 1234</TT></BLOCKQUOTE>
|
|
|
|
<BLOCKQUOTE><TT>$ (shell prompt from host.example.com)</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
By doing this, you create a fifo at /tmp/f and make nc listen at port 1234
|
|
of address 127.0.0.1 on
|
|
`server'
|
|
|
|
side, when a
|
|
`client'
|
|
|
|
establishes a connection successfully to that port, /bin/sh gets executed
|
|
on
|
|
`server'
|
|
|
|
side and the shell prompt is given to
|
|
`client'
|
|
|
|
side.
|
|
<P>
|
|
|
|
When connection is terminated,
|
|
<B>nc</B>
|
|
|
|
|
|
quits as well. Use
|
|
-<B>k</B>
|
|
|
|
if you want it keep listening, but if the command quits this option won't
|
|
restart it or keep
|
|
<B>nc</B>
|
|
|
|
|
|
running. Also don't forget to remove the file descriptor once you don't need
|
|
it anymore:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ rm -f /tmp/f</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>DATA TRANSFER</H2>
|
|
|
|
The example in the previous section can be expanded to build a
|
|
basic data transfer model.
|
|
Any information input into one end of the connection will be output
|
|
to the other end, and input and output can be easily captured in order to
|
|
emulate file transfer.
|
|
<P>
|
|
|
|
Start by using
|
|
<B>nc</B>
|
|
|
|
|
|
to listen on a specific port, with output captured into a file:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -l 1234 > filename.out</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Using a second machine, connect to the listening
|
|
<B>nc</B>
|
|
|
|
|
|
process, feeding it the file which is to be transferred:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -N host.example.com 1234 < filename.in</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
After the file has been transferred, the connection will close automatically.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>TALKING TO SERVERS</H2>
|
|
|
|
It is sometimes useful to talk to servers
|
|
``by hand''
|
|
|
|
rather than through a user interface.
|
|
It can aid in troubleshooting,
|
|
when it might be necessary to verify what data a server is sending
|
|
in response to commands issued by the client.
|
|
For example, to retrieve the home page of a web site:
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
$ printf "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
Note that this also displays the headers sent by the web server.
|
|
They can be filtered, using a tool such as
|
|
<A HREF="/cgi-bin/man/man2html?1+sed">sed</A>(1),
|
|
|
|
|
|
if necessary.
|
|
<P>
|
|
|
|
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:
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
$ nc [-C] localhost 25 << EOF
|
|
HELO host.example.com
|
|
MAIL FROM:<<A HREF="mailto:user@host.example.com">user@host.example.com</A>>
|
|
RCPT TO:<<A HREF="mailto:user2@host.example.com">user2@host.example.com</A>>
|
|
DATA
|
|
Body of email.
|
|
.
|
|
QUIT
|
|
EOF
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>PORT SCANNING</H2>
|
|
|
|
It may be useful to know which ports are open and running services on
|
|
a target machine.
|
|
The
|
|
-<B>z</B>
|
|
|
|
flag can be used to tell
|
|
<B>nc</B>
|
|
|
|
|
|
to report open ports,
|
|
rather than initiate a connection. Usually it's useful to turn on verbose
|
|
output to stderr by use this option in conjunction with
|
|
-<B>v</B>
|
|
|
|
option.
|
|
<P>
|
|
|
|
For example:
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
$ nc -zv 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!
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The port range was specified to limit the search to ports 20 - 30, and is
|
|
scanned by increasing order (unless the
|
|
-<B>r</B>
|
|
|
|
flag is set).
|
|
<P>
|
|
|
|
You can also specify a list of ports to scan, for example:
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
$ nc -zv host.example.com http 20 22-23
|
|
nc: connect to host.example.com 80 (tcp) failed: Connection refused
|
|
nc: connect to host.example.com 20 (tcp) failed: Connection refused
|
|
Connection to host.example.com port [tcp/ssh] succeeded!
|
|
nc: connect to host.example.com 23 (tcp) failed: Connection refused
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The ports are scanned by the order you given (unless the
|
|
-<B>r</B>
|
|
|
|
flag is set).
|
|
<P>
|
|
|
|
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
|
|
-<B>w</B>
|
|
|
|
flag, or perhaps by issuing a
|
|
Qq Dv QUIT
|
|
|
|
command to the server:
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
$ 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
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>EXAMPLES</H2>
|
|
|
|
Open a TCP connection to port 42 of host.example.com, using port 31337 as
|
|
the source port, with a timeout of 5 seconds:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -p 31337 -w 5 host.example.com 42</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Open a UDP connection to port 53 of host.example.com:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -u host.example.com 53</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Open 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:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -s 10.1.2.3 host.example.com 42</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Create and listen on a
|
|
UNIX
|
|
stream socket:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -lU /var/tmp/dsocket</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Connect 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
|
|
<A HREF="/cgi-bin/man/man2html?1+ssh">ssh</A>(1);
|
|
|
|
|
|
see the
|
|
<B>ProxyCommand</B>
|
|
|
|
directive in
|
|
ssh_config5
|
|
|
|
|
|
for more information.
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -x10.2.3.4:8080 -Xconnect host.example.com 42</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
The same example again, this time enabling proxy authentication with username
|
|
``ruser''
|
|
|
|
if the proxy requires it:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ nc -x10.2.3.4:8080 -Xconnect -Pruser host.example.com 42</TT></BLOCKQUOTE>
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+cat">cat</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+ssh">ssh</A>(1)
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>AUTHORS</H2>
|
|
|
|
Original implementation by
|
|
An *Hobbit* Aq Mt <A HREF="mailto:hobbit@avian.org">hobbit@avian.org</A> .
|
|
|
|
<BR>
|
|
|
|
Rewritten with IPv6 support by
|
|
An Eric Jackson Aq Mt <A HREF="mailto:ericj@monkey.org">ericj@monkey.org</A> .
|
|
|
|
<BR>
|
|
|
|
Modified for Debian port by Aron Xu
|
|
Aq <A HREF="mailto:aron@debian.org">aron@debian.org</A> .
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>CAVEATS</H2>
|
|
|
|
UDP port scans using the
|
|
-<B>uz</B>
|
|
|
|
combination of flags will always report success irrespective of
|
|
the target machine's state.
|
|
However,
|
|
in conjunction with a traffic sniffer either on the target machine
|
|
or an intermediary device,
|
|
the
|
|
-<B>uz</B>
|
|
|
|
combination could be useful for communications diagnostics.
|
|
Note that the amount of UDP traffic generated may be limited either
|
|
due to hardware resources and/or configuration settings.
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="36"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="37"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="38"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="39"><A HREF="#lbAE">CLIENT/SERVER MODEL</A><DD>
|
|
<DT id="40"><A HREF="#lbAF">DATA TRANSFER</A><DD>
|
|
<DT id="41"><A HREF="#lbAG">TALKING TO SERVERS</A><DD>
|
|
<DT id="42"><A HREF="#lbAH">PORT SCANNING</A><DD>
|
|
<DT id="43"><A HREF="#lbAI">EXAMPLES</A><DD>
|
|
<DT id="44"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="45"><A HREF="#lbAK">AUTHORS</A><DD>
|
|
<DT id="46"><A HREF="#lbAL">CAVEATS</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:19 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|