【问题标题】:Without Manual intervention need to get complete telnet output无需人工干预即可获得完整的 telnet 输出
【发布时间】:2018-10-02 10:06:55
【问题描述】:

我需要在没有任何人工干预的情况下获得准确的 telnet 输出

-bash-4.2# echo exit | telnet localhost 22
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
Connection closed by foreign host.

-bash-4.2# telnet localhost 22
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
SSH-2.0-OpenSSH_7.4

这里使用telnet localhost 22时显示“SSH-2 OpenSSH_7.4”,但在echo exit | telnet localhost 22中没有显示

输出:

bash-4.2# echo exit | telnet localhost 22
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
Connection closed by foreign host.
telnet> quit
Connection closed.
-bash-4.2#

我也尝试过以下 cmets “连接已关闭。”

-bash-4.2# cat < /dev/tcp/localhost/22
SSH-2.0-OpenSSH_7.4
^C
-bash-4.2# echo exit | cat < /dev/tcp/localhost/22
SSH-2.0-OpenSSH_7.4  (I want to execute and close automatically)

【问题讨论】:

  • 您想要完成的究竟是什么?例如,如果您只需要捕获输出并编写输入脚本,则可以考虑使用 Netcat。如果这不是您的目标,请尝试更好地解释它。
  • 得到了答案老兄,我想捕获确切的输出,感谢您的时间
  • 当你有一个你喜欢的答案时,选择最适合你的答案,然后accept那个答案。

标签: linux shell tcp telnet


【解决方案1】:

你可以试试;

read a < /dev/tcp/localhost/22
echo "Output is $a"

$a 变量将包含文本“SSH-2.0-OpenSSH_7.4”。

【讨论】:

    【解决方案2】:

    Telnet 在一些初始步骤(连接?)后开始读取输入。
    在结束输入之前,您必须给 telnet 一些时间来启动。

    (sleep 1 ; echo quit) | telnet localhost 22
    

    不需要echo

    sleep 1 |telnet localhost 22
    

    避免在输出中出现一些垃圾

    sleep 1 |netcat localhost 22
    

    【讨论】:

    • 简直太棒了,非常感谢老兄:)
    猜你喜欢
    • 2011-09-02
    • 2022-07-24
    • 2021-10-27
    • 2017-05-19
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    相关资源
    最近更新 更多