to make netcat (nc) automatically terminate at end of transmission
nc -v 10.20.30.40 22
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 10.20.30.40:22.
SSH-2.0-OpenSSH_7.4
nc -v 10.20.30.40 22 </dev/null
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 10.20.30.40:22.
SSH-2.0-OpenSSH_7.4
Ncat: 0 bytes sent, 21 bytes received in 0.14 seconds.
Why this happens? PER: https://billauer.co.il/blog/2018/07/netcat-nc-stop-quit-disconnect/
netcat opens a bidirectional TCP link, passing one side’s stdin to the other side’s stdout and vice versa. When netcat is faced with an EOF on its standard input, it may or may not close the sending part of its TCP connection, depending on which version of netcat it is. If it indeed closed the the sending connection, a FIN TCP packet is sent to the other side. The netcat program on the other side receives this FIN packet, and may or may not quit, once again, depending on which version of netcat it is. If it did quit, it returns a FIN packet, closing the connection altogether.

浙公网安备 33010602011771号