Linux NC command Details

Source: Internet
Author: User
Tags unix domain socket

NetCat, a "Swiss Army Knife" in Web tools, has a version of Windows and Linux. Because it is short and short (the 1.84 version is 25k, the old version or the reduced version is even smaller), functional, is designed as a simple, reliable network tool, can transmit read and write data through TCP or UDP protocol. At the same time, it is a network application debug parser, because it can create a variety of different types of network connections as needed.
one, the version of the regular Linux distribution with Netcat (NC), even in the rescue mode CD is also provided by BusyBox a simple version of the NC tools. But different versions, the use of their parameters slightly different. NetCat Official Address: http://netcat.sourceforge.net/

references [[email protected] ~]# cat/etc/asianux-release asianux Release 2.0 (Trinity SP2) [[email protected] ~]# CAT/ETC/REDFLA G-release Red Flag DC Server Release 5.0 (Trinity SP2) [[email protected] ~]# type-a NC NC is/usr/bin/nc [email Protect ED] ~]# rpm-q NC nc-1.10-22

It is recommended to use man NC to see help before using. Here is a brief description of the 1.10 version on red Flag DC Server 5.0. Assume two server information:

Reference server1:192.168.228.221 server2:192.168.228.222

second, the common use of 1, remote copy files from Server1 copy files to Server2. Need to first on the Server2, with NC activation monitoring, Server2 run:

references [[email protected] tmp]# NC-LP 1234 > Install.log

Run on Server1:

references [[email protected] ~]# ll install.log-rw-r--r--1 root root 39693 December install.log [[email protected] ~]# NC -W 1 192.168.228.222 1234 < Install.log

2, clone hard disk or partition operation and the above copy is identical, only need to get the hard disk or partition data by DD, and then transfer. Cloning the operation of a hard disk or partition should not take place on a system already on mount. Therefore, after booting with the installation disc, enter rescue mode (or use the Knoppix tool CD) to boot the system and perform a similar listening action on the Server2:

# nc-l-P 1234 | DD OF=/DEV/SDA

Perform the transfer on Server1 to complete the task of cloning the SDA hard drive from Server1 to Server2:

# DD IF=/DEV/SDA | NC 192.168.228.222 1234

※ The prerequisite for completing the above work is to implement the CD rescue mode to support the network card on the server and properly configure the IP.
3. Port scan
can be performed:

Ref # NC-V-W 1 192.168.228.222-z 1-1000 hatest2 [192.168.228.222] (SSH) Open

4. Save the Web page

# while true; Do Nc-l-P 80-q 1 < somepage.html; Done

5. Analog HTTP Headers

references [[email protected] ~]# NC www.linuxfly.org get/http/1.1 Host:ispconfig.org Referrer:mypage.com User-agent:my-bro Wser
http/1.1 date:tue, Dec 07:23:24 GMT server:apache/2.2.6 (Unix) dav/2 mod_mono/1.2.1 mod_python/3.2.8 Pyth on/2.4.3 mod_perl/2.0.2 perl/v5.8.8 Set-cookie:phpsessid=bbadorbvie1gn037iih6lrdg50; path=/expires:0 Cache-control:no-store, No-cache, Must-revalidate, post-check=0, pre-check=0 Pragma:no-cache Cache-Co Ntrol:private, Post-check=0, pre-check=0, max-age=0 Set-cookie:own_sid=xrutay; Expires=tue, 23-dec-2008 07:23:24 GMT; path=/vary:accept-encoding transfer-encoding:chunked content-type:text/html [...]

After the NC command, enter the contents of the Red section and press ENTER two times to get the HTTP headers content from the other side.
6, Chat NC can also be used as a simple word hyphenating chat tool, the same, server2 need to start monitoring:

[Email protected] tmp]# NC-LP 1234

Server1 on transfer:

[[Email protected] ~]# NC 192.168.228.222 1234

In this way, the two sides can communicate with each other. Use Ctrl+d to exit normally.
7, the transmission directory from Server1 copy nginx-0.6.34 directory contents to Server2. Need to first on the Server2, with NC activation monitoring, Server2 run:

references [[email protected] tmp]# nc-l 1234 |tar XZVF-

Run on Server1:

references [[email protected] ~]# ll-d nginx-0.6.34 drwxr-xr-x 8 + 4096 12-23 17:25 nginx-0.6.34 [[email protected] ~]# TA R CZVF-NGINX-0.6.34|NC 192.168.228.222 1234

8, Parameter introduction This is only a simple 1.10 version of the description, the detailed parameters to use or need to look at the man:

References want to connect to somewhere: NC [-options] hostname port[s] [ports] ... Bind port Waiting for connection: Nc-l-P Port [-options] [hostname] [port] Parameter:-G gateway source-routing Hop Point[s], up to 8-g num Source-rou Ting Pointer:4, 8, ...-H help information-i secs time-out interval-l listening mode, for inbound connection-n Specifies the IP address of the number, cannot be transmitted with the Hostname-o file 16-in-port port local port number -R arbitrarily specify local and remote port-S addr Local Source address-u UDP mode-v Verbose output--with two-V to get more detailed content----secs timeout time

-Z turns the input and output off-when used for scanning, where the port number can specify one or a specified range of Lo-hi.

Introduction to the 9, 1.84 version parameters 1.&NBSP;NC [ -46DDHKLNRSTUUVZC] [-I interval] [-p source_port] 2.    [-S source_ip_address] [-t ToS] [-W Tim Eout] [-X Proxy_protocol] [-X 3.    proxy_address[:p ort]] [hostname] [port[s]]   1. -4 forced use IPv4 2. -6 mandatory use of IPv6 3. -d allows socket traffic to return debug information 4.      -D does not allow reading from standard input 5. -h Displays the NC Help document 6. -i interval  7.    Specifies that the content is delayed sent and accepted between each line, or that the connection between multiple ports is delayed 8. -k when a connection ends, Forces the NC to listen on another connection. 9. -l must be used with-l to listen for incoming data links and cannot be used with-p-z-S. The time-out of the-W parameter is also ignored 10. -n does not perform any address, hostname, port, or DNS query 11. -p specifies the source port that NC uses, is restricted by permission and cannot be used together with 12. -r to specify the source and destination ports that NC uses. You cannot use the port 13. -s that the system originally specified to allow TCP MD5 signing options in RFC 2385 14. -s source_ip_address  15.    Specifies the IP address of the interface used for the package, and cannot use the 16. -t ToS 17.    with-l to specify the linked IP service type (ToS) 18. -c Wrap 19. -t Enables NC to interact with Telnet 20. -u using the UNIX domain socket 21. -u using UDP instead of the default TCP option 22.&NBSP;-V output verbose report 23. -w timeout 24. & nbsp;   AThe link has no action for a period of time, then automatically disconnects, default no timeout 25. -x proxy_version 26.     Specifies the protocol used by the NC to use the proxy, optional SOCKSV4, SOCKS5 and HTTPS. The default SOCKS5 27. -x proxy_address[:p ort] 28.     Specifies the proxy address and port used by the NC. Default settings: SOCKS, 3128 (HTTPS) 29. -z only listen for no packets sent

  Three, version difference the NC version provided on the system will be different, and the parameters used by it may vary slightly. For example, the red Flag Asianux 3.0 SP1 Rescue CD version is available for use with only a subset of parameters:

Ref # Nc-h BusyBox v1.2.0 (2008.04.14-01:35+0000) multi-call binary
USAGE:NC [OPTIONS] [IP] [port]
Netcat opens a pipe to Ip:port
Options:-L Listen mode, for inbound connects-p port local port number-          I SECS delay interval for lines SENT-E PROG program to exec after connect (dangerous!) -W SECS timeout for connects and final net reads

The NC version provided in the Asianux 3.0 SP1 system is 1.84, which is not executed according to the above parameter usage:

references [[email protected] ~]# rpm-q NC nc-1.84-10 [[email protected] ~]# NC-LP 1234 USAGE:NC [ -46DDHKLNRSTUUVZC] [-I Interva l] [-P source_port] [-S source_ip_address] [-t ToS] [-w timeout] [-X proxy_version] [-X Proxy_addres s[:p ORT] [hostname] [port[s]]

To view the man document, it is visible in this version,-L is not used with-s,-P,-Z, and the-w parameter is ignored, so the correct usage is:

[Email protected] tmp]# nc-l 1234

Four, in the script in the NC each time you start listening, the client connection is completed and exited at the same time, the service side exits together. So, if you need to constantly use NC for data transfer, you need to use loops in your scripts. Using NC For more functionality, refer to the reference script provided by its RPM:

Ref # RPM-QD Nc/usr/share/doc/nc-1.10/changelog/usr/share/doc/nc-1.10/readme/usr/share/doc/nc-1.10/scripts/readme/ Usr/share/doc/nc-1.10/scripts/alta/usr/share/doc/nc-1.10/scripts/bsh/usr/share/doc/nc-1.10/scripts/dist.sh/usr /share/doc/nc-1.10/scripts/irc/usr/share/doc/nc-1.10/scripts/iscan/usr/share/doc/nc-1.10/scripts/ncp/usr/share /doc/nc-1.10/scripts/probe/usr/share/doc/nc-1.10/scripts/web/usr/share/doc/nc-1.10/scripts/webrelay/usr/share/ Doc/nc-1.10/scripts/websearch/usr/share/man/man1/nc.1.gz

Linux NC command Details

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.