Detailed explanation of linux nc command parameters and usage 1. Function Description: powerful network tool netcat 2. Syntax: nc [options] [options]-d background mode-e prog program redirection. Once connected, run [dangerous!] -G <gateway> you can set up to eight vro communication gateways. -G <Number of pointers> sets the source route indicator, which is a multiple of 4. -I <latency in seconds> latency interval-l listening mode. It is used to continue listening after the inbound connection-L connection is closed.-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 <port> set the communication port used by the local host. -R random local and remote ports-s <source IP address> set the IP address of the local host to send packets. -T use TELNET interaction mode-u uses UDP transmission protocol. -V detailed output (two-v can be used to obtain more details)-w <timeout seconds> sets the waiting time, that is, the number of seconds after the specified disconnection. -Z uses the 0 input/output mode and is only used when scanning communication ports. -H help information host name/ip specifies the access host name/ip port listens to the port of the remote host, which can be a single or a range (M-N ). 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...] 3. Application ① port scan (usually used to check whether a service [port] of an ip address is monitored, that is, whether a service is started) format: nc-v-w 2-z $ ip $ port-v shows the command execution process. -W <timeout seconds> sets the waiting time. -Z uses the 0 input/output mode and is only used when scanning communication ports. ② Remote data transmission (source host ----> destination host ($ ip needs to listen to the port ). Ctrl + c breaks the connection after the file is uploaded. disadvantage: you do not know when the file is uploaded. Format: Remote (destination) Host: nc-l $ port> $ file source host: nc $ ip $ port <$ file ③ simple and timely chat (you need to listen to the port $ port on a host, and other hosts can connect and chat, Ctrl + c, ctrl + d Exit) Format: Remote (destination) Host: nc-l $ port source host: nc $ ip $ port ④ hard disk or partition (same as ②, source host ----> the target host should not be used to clone the hard disk or partition on the mounted system .) Format: Remote (destination) Host: nc-l $ port | dd of = partition source host: dd if = partition | nc $ ip $ port 4. Example ① batch check the server's specified port opening status: 1. if we want to monitor a bunch of specified IP addresses and ports, you can create a new file (1st server IPs and 2nd ports to be monitored ). # Vim/scripts/ip-ports.txt 192.168.0.100 80 192.168.0.100 8081 192.168.0.101 8082 192.168.1.100 21 2, we can write such a script to check whether the port is open in batches: # vim/scripts/ncports. sh #! /Bin/bash # Check whether the server port is open. If the port is successful, the return value is 0. OK is displayed, failure Returns a value of 1 showing fail cat/scripts/ip-ports.txt | while read line do nc-w 10-z $ line>/dev/null 2> & 1 if [$? -Eq 0] then echo $ line: OK else echo $ line: fail fi done 3. Run the script to view the running result as follows: # chmod a + x/scripts/ncports. sh #/scripts/ncports. sh 192.168.0.100 80: OK 192.168.0.100 8081: OK 192.168.0.101 8082: OK 192.168.1.100 21: fail