2
我需要創建一種方法來傳遞命令並將文件從主機服務器傳輸到開發板。使用netcat的通信協議
- 唯一通過主機服務器(有線以太網連接)訪問主板。
- 主機服務器和主板都在運行Linux。
- 我有能力改變電路板上的Linux環境。
- 我沒有能力改變主機服務器環境。
- 我不知道哪些用戶需要連接到電路板。
- 主機服務器和主板之間的連接不需要安全。
現在,我正在使用netcat滿足我的需求,但遇到了可靠性問題 - 有人可以指點我一些更適合我的需求和更高性能的工具嗎?
我目前的解決方案:
的腳本不斷在板上運行:
while [ 1 ] ; do
# Start a netcat server, awaiting a file.
nc -l -p 1357 > file.bin
# Acknowledge receipt of file.
status=fail
while [ ${status} -ne 0 ] ; do
status=$(echo 0 | nc <host_ip> 2468 2>&1)
done
# Wait for a command.
nc -l -p 1357 -e /bin/sh
# Acknowledge receipt of command.
status=fail
while [ ${status} -ne 0 ] ; do
status=$(echo 0 | nc <host ip> 2468 2>&1)
done
done
用戶都可以訪問該板的唯一方法是通過服務器上的腳本:
# Send over a file.
cat some_file.bin | /bin/nc -w 10
# Wait for acknowledge.
if [ $(nc -l 2468) -ne 0 ] ; then
exit # Fail
fi
# Send a command.
echo "<some_command>" | nc -w 10 <board ip> 1357
# Wait for acknowledge.
if [ $(nc -l 2468) -ne 0 ] ; then
exit # Fail
fi
我使用netcat的,現在的原因是,我不知道任何方式使用SSH或SCP沒有密碼考慮到:
- 我無法爲每個人都需要訪問到電路板上,尤其是因爲我不知道誰將會使用它SSH密鑰。
- 我無法安裝sshpass或期望,因爲我沒有控制服務器。
請幫忙, 謝謝。
沒有OPs語句'我沒有能力更改主機服務器環境。'排除'修改主機上的SSH客戶端配置'?祝你們好運。 – shellter
@shellter如果OP能夠在主機上運行'ssh board',他也應該能夠運行'ssh -o HostbasedAuthentication board'。 – damienfrancois