Linux NC Detailed

Source: Internet
Author: User
Tags md5 rfc stdin unix domain socket

Feature Description: Powerful networking tools

Netcat (NC) is a simple and useful tool that can not only read and write data through a network connection using TCP or UDP protocol, but also a powerful network debugging and probing tool to build almost all types of network connections you need.

Installation:

[email protected]/0 # yum -y install nc

Help:

[Email protected]/0 # NC-HUSAGE:NC [ -46DDHKLNRSTUUVZC] [-I interval] [-P source_port] [-S Source_ip_addres s] [-t ToS] [-w timeout] [-X proxy_version] [-X proxy_address[:p ort]] [hostname] [port[s]] Command Summary :-4 Use ipv4-6 use ipv6-d Enable th                E Debug socket option-d Detach from stdin-h this help text  -I secs Delay interval for lines sent, ports scanned-k Keep inbound sockets              Open for multiple connects-l Listen mode, for inbound connects-n              Suppress Name/port resolutions-p Port specify local port for remote CONNECTS-R Randomize remote Ports-s Enable the TCP MD5 signature Option-s A DDR Local Source Address-t ToS Set IP Type of Service-c Send CRLF as Line-ending                -T Answer TELNET negotiation-u use UNIX domain socket -U UDP mode-v verbose-w secs Timeout for connects and F  inal Net Reads-x Proto Proxy protocol: "4", "5" (SOCKS) or "Connect"-X addr[:p ORT] Specify proxy address and port-z zero-i/o mode [used for scanning] port numbers can b e individual or Ranges:lo-hi [inclusive]

Man manual translation:

NAME nc-an arbitrary TCP and UDP connection and Monitoring tool synopsis NC [ -46BCDDHKLNRSTUUVZZ] [-I length] [-I interval] [-O length] [-P Proxy_use Rname] [-P source_port] [-Q seconds] [-s source] [-t Toskeyword] [-v rtable] [-w timeout] [-X Proxy_protoco l] [-X proxy_address[:p ORT]] [destination] [port]description NC (or netcat) utility for any TCP, UDP, or Unix-domain sockets  Scene [not how can translate this, according to the general meaning of the original text: the NC (or netcat) utility is used for just about anything under the sun involving TCP, UDP,         or Unix-domain sockets.].         It can open TCP connections, send UDP packets, listen to arbitrary TCP and UDP ports, implement port scanning, and simultaneously handle IPV4 and IPV6.     Unlike Telnet (1), NC scripts are nice and output error messages to standard errors instead of standard output, as Telnet (1) does with some.   Common uses include: •   Simple TCP Proxy ·   Shell scripts based on HTTP client and server ·   Network Daemon Testing ·   A SOCKS or HTTP proxy command line for SSH (1) ·     There are many more, many of which have the following options available:-4 Force NC to use only IPv4 addresses.     -6 Force NC to use only IPV6 addresses.     -B allows broadcasting.     -C sends CRLF as a newline character.     -D open debugging in socket. -D does not attempt to read from stdinData.     -H Print NC help information.     -I length specifies the TCP receive buffer size.  -I interval specifies the delay time for text lines to be sent and received.     It is also possible to create delays that are connected to multiport ports.  -K forces NC to continuously listen on another connection until its connection is complete.     The-l option is not an error.  -L is used to specify that the NC should listen for an incoming connection instead of connecting to a remote host.  This option cannot be used in conjunction with the following options-p,-S, or-Z options.     In addition, any timeout specified with the-w option is ignored.     -N any specified address, hostname or port does not do any DNS or service resolution.     -O length Specifies the size of the TCP send buffer. -P proxy_username Specifies a user name to the proxy server used to request authentication. If no user name is specified then authentication will not be attempted.     The proxy authentication feature currently only supports HTTP connect proxies.     -P source_port Specifies the source port that NC uses, subject to permissions and availability restrictions. -Q seconds after stdin EOF, wait for a specified number of seconds before exiting.     If the number of seconds is negative, wait forever.     -r specifies that the source and/or destination ports are randomly selected instead of a range sequence or system allocation order.     -S turns on the RFC 2385 TCP MD5 signature option.  -S source specifies that the IP interface is used to send packets. For Unix-domain datagram sockets, specifies that a local temporary socket file is created and used so that datagrams can be received.     You cannot use the-l option at the same time.  -T Toskeyword change the IPV4 tos value. Toskeyword May is one of critical, Inetcontrol, Lowcost, Lowdelay, Netcontrol, throughput, reliability, or on E of the DiffServ Code Points:EF, af11 ... af43, cs0 ... cs7 (this sentence will not translate);      or a hexadecimal or decimal number. -T raises the NC send RFC 854 DON ' The WON ' t response to RFC 854 do and would requests.     This makes it possible to use a NC scripted telnet session.     -U limits the use of Unix-domain sockets. -U uses UDP instead of the default TCP option.             For Unix-domain sockets, use a datagram socket instead of a stream socket.     If the unix-domain socket is used, a temporary receiving socket is created in/TMP unless the-s flag is given. -V rtable sets the route table to use.     The default is 0.     -V causes the NC to give more verbose output.               -W timeout could not be established or idle connections timed out after a specified number of seconds. The-W flag does not affect the-l option, for example.  NC will continuously listen for a connection, regardless of the-w flag.     The default is no timeout.  -X Proxy_protocol requires the NC to connect to the proxy server using the specified protocol.             The supported protocols are "4" (SOCKS V.4), "5" (SOCKS V.5) and "Connect" (HTTPS proxy).     If you do not specify a protocol, SOCKS version 5 will be used. -X proxy_address[:p ORT] requires NC to connect to the destination using the specified proxy address and port.     If you do not specify a port, use the default proxy protocol port (for SOCKS, 3128 for HTTPS).     -Z DCCP mode (Datagram Congestion Control Protocol).  -Z Specifies that the NC simply scans the daemon that is listening and does not send any data.     cannot be used in conjunction with the-l option.      The target can be a numeric IP address or a character hostname (except for the specified-n option). In general, you must specify a target unless you give the-l option (in which case the local masterMachine). For Unix-domain sockets, a target is necessary, and a socket path is used to connect (or listen if the-l option is given).  The port can be an integer or a range of port numbers. The port range specifies nn-mm using this format. In general, a destination port must be specified unless the-u option is given. client/server mode using NC to build a very basic client/server model is very simple. On a console, open the NC listener on a specified port to wait for the connection. Example: $ nc-l 1234 NC is now listening on port 1234 waiting for a connection. On the second console (or second machine), connect to the host port being monitored: $ NC 127.0.0.1 1234 The connection should now be established between the ports.  Any typing on the second console will be threaded to the first console and vice versa. After the connection is established, NC does not really care which side is used for the ' server ' and which side is used for ' client '.     The connection can be interrupted with EOF (' ^d ').     There is no-C or-e option in this netcat, but you can still execute a command after the connection is established through the file Descriptor redirection form.     Be careful here, because opening a port allows anyone to connect and execute arbitrary commands on your site is very dangerous. If you really want to do this, here is an example: on the ' server ' side: $ rm-f/tmp/f; Mkfifo/tmp/f $ cat/tmp/f | /bin/sh-i 2>&1 | Nc-l 127.0.0.1 1234 >/tmp/f in ' client ': $ NC host.example.com 1234 $ (Shell prompt from Host.exam ple.com) Through this step, you create a FIFO on the ' server ' side of the/tmp/f and make the NC listener address 127.0.0.1 1234 Port, when a ' client ' establishes a connection successfully to that port,/bin/sh executes on the ' server ' side and gives ' client ' s     Hell prompt. NC also exits when the connection is terminated. If you want to keep listening, use-K, but this option will not restart it or keep NC running when the command exits (this translationGood awkward, post the original reference: But if the command quits this option won ' t restart it or keep NC running.) Also don't forget to delete the file descriptor when you no longer need it: $ rm-f/tmp/f The example of a region before data transfer can be extended to build a basic data transfer pattern.     One end of any information input will be output through the connection to the other end, and the inputs and outputs can be easily captured for file transfers.  First Use NC to listen to a specified port, and capture output to a file: $ nc-l 1234 > Filename.out Use the second machine, connect to the NC process listening on this port, feed it to the file to be transferred: $ NC Host.example.com 1234 < filename.in The connection closes automatically after the file has been transferred. Talking to the server sometimes "manual" and server chat is more useful than through a user interface. This can help resolve the failure when it is necessary to verify the client-initiated request and what data the server sends to respond to the command line. For example, testing website home: $ printf "get/http/1.0\r\n\r\n" |  NC host.example.com 80 Note This also shows the headers sent by the Web server.     They can use tools such as sed (1) To filter, if necessary. More complex examples can also be built when the user knows the request format that the server needs. For example, an email can be submitted to an SMTP server using the following methods: $ NC [-c] localhost << EOF HELO host.example.com M AIL from:<[email protected]> RCPT to:<[email protected]> DATA Body of           Email.           . The QUIT EOF port scan wants to know which ports are open on the target machine andand running the service can be useful.     The-Z flag can be used to tell the NC to report an open port instead of initializing a connection.     It is often useful to open verbose output to stderr by federating with the-v option.           For example: $ nc-zv host.example.com 20-30 Connection to host.example.com Port [Tcp/ssh] succeeded!     Connection to host.example.com Port [TCP/SMTP] succeeded!     The port range is limited to scan 20-30, through ascending. You can also specify a list of ports to scan, for example: $ nc-zv host.example.com nc:connect to host.example.com (TCP) fail Ed:connection refused Nc:connect to host.example.com (TCP) Failed:connection refused Connection     to host.example.com Port [Tcp/ssh] succeeded!     The port scan order is determined by the order you have given. Or, which version might be useful for knowing which server-side software is running.     This information is usually included in the greeting banners.     In order to obtain this information, it is necessary to make a connection first and then destroy the connection when the banner gets to it. This can be obtained by specifying a short time-out with the-w flag, or by sending a "quit" command to the server: $ echo "Quit" |           NC host.example.com 20-30 ssh-1.99-openssh_3.6.1p2 Protocol mismatch. host.example.com IMS SMTP Receiver Version 0.84 Ready Other paradigm open a TCP connection to host.example.com 42 port, using 31337 as the source port, and set the 5-second timeout: $ nc-p 31337-w 5 host.example.com 42 open a UDP connection to the Host.example.com 53 port: $ NC- U host.example.com 53 Open a TCP connection to host.example.com 42 port, using 10.1.2.3 as the local-side IP for connection: $ nc-s 10.1.2.3 host.example.c Om 42 creates and listens for a unix-domain stream socket: $ nc-lu/var/tmp/dsocket connected to host.example.com 42 port via 8 on 10.2.3.4     HTTP proxy connection for Port 080. This example can also be implemented using SSH (1);           For more information, refer to proxycommand directive in Ssh_config (5). $ nc-x10.2.3.4:8080-xconnect host.example.com 42 The same example, this time using the "Ruser" username to open the proxy authentication, if the agent needs authentication: $ nc-x10.2.3.4:80 80-xconnect-pruser host.example.com 42SEE ALSO Cat (1), SSH (1) AUTHORS Original implementation by *hobbit* [email&     Nbsp;protected]?.     Rewritten with IPV6 support by Eric Jackson <[email protected]>. Modified for Debian Ports by Aron Xu [email protected]?. Caveats UDP port scans using THE-UZ combination of flags would always report success irrespective of the target Machin E ' s state.       However, in conjunction with a traffic sniffer either on the target machine or an intermediary device, The-uz     Combination could is useful for communications diagnostics. Note that the amount of UDP traffic generated is limited either due to hardware resources and/or configuration set Tings.

A little more practical example of an advanced point

nc -l 1234 |tar -xvf - #目标机上执行tar -cvf - 目录 |nc 目标机IP 1234 #在被迁移机上执行 #能实现块级别的压缩迁移 。速度是最快的。遇到大量零碎小文件要同步的时候很有用。

Linux NC Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.