收到数据后如何关闭netcat连接?

问题描述 投票:0回答:1

下面是netcat的一个非常简单的用法:

#!/bin/sh

echo "hello world" > original.txt
base64 original.txt > encoded.txt
cat encoded.txt | nc -l -p 1234 -q 0
#!/bin/sh

nc localhost 1234 -q 0 > received.txt
base64 -d received.txt > decoded.txt
rm received.txt encoded.txt
echo "Sent:"
md5sum original.txt
echo "Received:"
md5sum decoded.txt
rm decoded.txt original.txt

[这将创建一个文件,将其编码为base64,通过netcat发送,然后对其进行解码,最后使用校验和比较来比较发送的内容和接收的内容是否相同。

[在我先前使用的Kali Linux机器上,netcat连接在执行第二个脚本时关闭,但是在家里的Ubuntu上尝试,情况并非如此。我需要使用Ctrl+D手动关闭连接。

如何接收数据后关闭连接?

bash netcat
1个回答
0
投票

我认为应该为-c包含nc标志。另外,您确定要使用Bourne Shell,而不是Bash吗?我建议将您的shebang更改为#!/bin/bash

© www.soinside.com 2019 - 2024. All rights reserved.