Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Linuxnc Command & lt; netcat & gt; function description: powerful network tool syntax: nc [-hlnruz] [-g & lt; gateway... & gt;] [-G & lt; number of pointers & gt;] [-I & lt; delay seconds & gt;] [-o & lt; output file & gt;] [-p & lt; communication Port & gt;] [-s & lt; source address & gt;] [-v...] linux nc commands Function description: powerful network tool syntax: nc [-hlnruz] [-g <网关...> ] [-G <指向器数目> ] [-I <延迟秒数> ] [-O <输出文件> ] [-P <通信端口> ] [-S <来源位址> ] [-V...] [-w <超时秒数> ] [Host name] [communication port...] parameter:-g <网关> Set the maximum number of vro communication gateways. -G <指向器数目> Set the source route pointing device. its value is a multiple of 4. -H online help. -I <延迟秒数> Set the time interval to send information and scan the communication port. -L use the listener mode to control incoming data. -N directly uses the IP address instead of the domain name server. -O <输出文件> Specify the file name, and dump the data that is being transferred in hexadecimal format into the file for storage. -P <通信端口> Set the communication port used by the local host. -R: specifies the communication port between the local host and the remote host. -S <来源位址> Set the IP address of the data packet sent from the local host. -U uses UDP transmission protocol. -V shows the command execution process. -W <超时秒数> Set the waiting time. -Z uses the 0 input/output mode and is only used when scanning communication ports. Extended Information 1: nc simple use example 1) port scan # nc-v-w 2 192.168.2.34-z 21-24nc: connect to 192.168.2.34 port 21 (tcp) failed: connection refusedConnection to 192.168.2.34 22 port [tcp/ssh] succeeded! Nc: connect to 192.168.2.34 port 23 (tcp) failed: Connection refusednc: connect to 192.168.2.34 port 24 (tcp) failed: Connection refused 2) copy a file from 192.168.2.33 to 192.168.2.34 at 192.168.2.34: nc-l 1234> test.txt on 192.168.2.33: nc 192.168.2.34 <test.txt 3) simple chat tool on 192.168.2.34: nc-l 1234 on 192.168.2.33: nc 192.168.2.34 1234, the two sides can communicate with each other. Use ctrl + C (or D) to exit. 3. run the nc Command to operate memcached1) store data: printf "set key 0 10 6rnresultrn" | nc 192.168.2.34 112112) get data: printf "get keyrn" | nc 192.168.2.34 112113) delete data: printf "delete keyrn" | nc 192.168.2.34 112114) view status: printf "statsrn" | nc 192.168.2.34 112115) simulate top Command View status: watch "echo stats" | nc 192.168.2.34 112116) clear Cache: printf "flush_allrn" | nc 192.168.2.34 11211 (careful operation, the cache is cleared) nc-l 1234 nc 127.0.0.1 1234 establish a connection on port 1234 and send the input nc-p to each other 1234-w 5 host.example.com 80 establish a connection from the local port 1234 to port 80 of host.example.com, 5 Seconds of timeout nc-u host.example.com 53u for UDP connection echo-n "GET/HTTP/1.0" r "n" r "n" | nc host.example.com 80 connect to the host and execute nc-v -z host.example.com 70-80 scan port (70 to 80 ), you can specify a range. -V: output details. Extended Information 2: I do not describe how to use the linux nc Command to transmit a file nc. today I will focus on using nc to transfer files. The reason is that the company's device sudo does not have ssh, scp, or other remote access commands, or the host. deny contains ssh deny. Today, I used scp to illustrate the next more useful lightweight tool, another powerful feature of nc-file transfer. Example: target host listening nc-l listening port> file name to be received nc-l 4444> cache.tar.gz source host initiating request nc target host ip address destination port nc 192.168.0.85 4444 netstat as follows [root @ localhost jiangbao] # netstat-tpln tcp 0 0 0.0.0.0: 4444 0.0.0.0: * LISTEN 18166/nc the following DATA TRANSFERStart by using nc to listen on a specific port, with output captured into a file: $ nc-l 1234> filename. outUsing a second machine, connect to the listening nc process, feeding it The file which is to be transferred: $ nc host.example.com 1234 extended Document 3: linux nc (NetCat) command details. This article introduces nc in great detail, which is partially duplicated in the above documents. i. The common Linux releases contain NetCat (nc), and busybox provides a simplified nc tool even in the rescue mode. However, the parameters of different versions vary slightly. [Root @ hatest1 ~] # Cat/etc/asianux-releaseAsianux release 2.0 (Trinity SP2) [root @ hatest1 ~] # Cat/etc/redflag-releaseRed Flag DC Server release 5.0 (Trinity SP2) [root @ hatest1 ~] # Type-a ncnc is/usr/bin/nc [root @ hatest1 ~] # Rpm-q ncnc-1.10-22 is recommended before use, use man nc to see help. Here we will briefly describe the 5.0 version of the red-flag DC Server 1.10. Assume that the information of the two servers is: reference server1: 192.168.228.221server2: 192.168.228.222 2. Common use 1. Remote Copy of a file from server1 to server2. Run [root @ hatest2 tmp] # nc-lp 1234> install. logserver1: reference [root @ hatest1 ~] # Ll install. log-rw-r-1 root 39693 2007 install. log [root @ hatest1 ~] # Nc-w 1 192.168.228.222 1234 <install. log 2. the clone hard disk or partition operation is the same as the copy operation above. you only need to obtain the data of the hard disk or partition by dd, and then transmit it. Cloning a hard disk or partition should not be performed on a mounted system. Therefore, you need to use the installation CD boot, enter the rescue mode (or use the Knoppix tool CD) to start the system, and then perform similar listening actions on server2: # nc-l-p 1234 | dd of =/dev/sda server1 to complete the task of cloning sda 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 NIC on the server and correctly configure the IP address. 3. port scan can be performed: reference # nc-v-w 1 192.168.228.222-z 1-1000hatest2 [192.168.228.222] 22 (ssh) open 4. Save the Web page # while true; do nc-l-p 80-q 1 <somepage.html; done 5. simulate HTTP Headers reference [root @ hatest1 ~] # Nc www.linuxso.com 80GET/HTTP/1.1 Host: ispconfig. orgReferrer: mypage. comUser-Agent: my-browser HTTP/1.1 200 OKDate: Tue, 16 Dec 2008 07:23:24 GMTServer: Apache/2.2.6 (Unix) DAV/2 mod_mono/1.2.1 mod_python/3.2.8 Python/2.4.3 mod_perl/2.0.2 Perl/v5.8.8Set-Cookie: PHPSESSID = empty; path =/Expires: 0Cache-Control: no-store, no-cache, must-revalidate, post-check = 0, pre-check = 0 Prag Ma: no-cacheCache-Control: private, post-check = 0, pre-check = 0, max-age = 0Set-Cookie: oWn_sid = xRutAY; expires = Tue, 23-Dec-2008 07:23:24 GMT; path =/Vary: Accept-EncodingTransfer-Encoding: chunkedContent-Type: text/html [......] after running the nc Command, enter the content in red and press enter twice to obtain the HTTP Headers content from the other party. 6. chat nc can also be used as a simple chat tool under characters. Similarly, Server 2 needs to start listening: [root @ hatest2 tmp] # nc-lp 1234 server1 transmission: [root @ hatest1 ~] # Nc 192.168.228.222 1234 so that the two parties can communicate with each other. Use Ctrl + D to exit normally. 7. the transfer directory copies the contents of the nginx-0.6.34 directory from server1 to server2. You must first activate the listener with nc on server2. run the following command on server2: reference [root @ hatest2 tmp] # nc-l 1234 | tar xzvf-server1: reference [root @ hatest1 ~] # Ll-d nginx-0.6.34drwxr-xr-x 8 1000 1000 12-23 nginx-0.6.34 [root @ hatest1 ~] # Tar czvf-nginx-0.6.34 | nc 192.168.228.222 1234 8, parameter introduction this is only a simple description of version 1.10, the detailed parameter use still need to see man: reference want to connect to somewhere: nc [-options] hostname port [s] [ports]… Bind the port to wait for the connection: nc-l-p port [-options] [hostname] [port] parameter:-g gateway source-routing hop point [s], up to 8-G num source-routing pointer: 4, 8, 12 ,... -H help information-I secs delay interval-l listening mode, used for inbound connection-n specified number IP address, the hostname-o file cannot be used to record the hexadecimal transmission-p port local port number-r arbitrarily specify the local and remote ports-s addr local source address-u UDP mode-v detailed output-use two-v to get more detailed content-w secs timeout time-z turn off the input and output-for scanning, you can specify one port number or a range in the lo-hi format. 3. Version differences do not apply to the nc version provided by the system. the parameter usage varies slightly. For example, the version on the Hongqi Asianux 3.0 SP1 rescue disc is only available in part: reference # nc-hBusyBox v1.2.0 (2008.04.14-0+ 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, while the nc version provided in Asianux 3.0 SP1 is 1.84, which cannot be executed according to the preceding parameter usage: reference [root @ ftpserver ~] # Rpm-q ncnc-1.84-10 [root @ ftpserver ~] # Nc-lp 1234 usage: nc [-46 DdhklnrStUuvzC] [-I interval] [-p source_port] [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version] [-x proxy_address [: port] [hostname] [port [s] View man's document. in this version,-l cannot be used with-s,-p, and-z, the-w parameter is ignored, so the correct usage is: [root @ ftpserver tmp] # nc-l 1234 4. after each listener is started by nc in the script, when the client connection is complete and exits, the server exits together. Therefore, if you need to continuously use nc for data transmission, you need to use loops in the script. To use nc to implement more functions, refer to the reference script provided by its rpm: reference # 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/webproxy/usr/share/doc/ nc-1.10/scripts/webrelay/usr/share/doc/nc-1.10/scripts/websearch/usr/share/man/man1/nc.1.gz
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
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:
and provide relevant evidence. A staff member will contact you within 5 working days.