Twisted Conch MockSSH:实现“stty echo”

2024-05-19 08:35:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使用MockSSH设置一个模拟sshshell服务器。在

为了测试我正在处理的特定应用程序,我需要能够阻止shell回显输入。应用程序总是通过发出“stty-echo”命令启动,这样stdout只包含输出。 例如:

user@host> echo "hello world"
hello world
user@host> stty -echo
user@host>
hello world
user@host>
I swear I just typed 'echo "hello world"'!

默认情况下禁用echo,或者在发出“stty-echo”命令时禁用echo也同样有效。在


Tags: 命令echo服务器应用程序hosthelloworldstdout
1条回答
网友
1楼 · 发布于 2024-05-19 08:35:54

经过几天的努力,我找到了一个对我的目标有效的解决方案,他说自我终端写入(ch)“从SSHProtocol实现的characterReceived方法中完全禁用了输入打印,就像在bash中运行了'stty-echo'命令一样。在

class SSHProtocol(recvline.HistoricRecvLine):
    [...]
    def characterReceived(self, ch, moreCharactersComing):
        self.lineBuffer[self.lineBufferIndex:self.lineBufferIndex+1] = [ch]
        self.lineBufferIndex += 1

        #if not self.password_input:
        #    self.terminal.write(ch)

就我的目的而言,我相信您可以很容易地在SSH协议中设置一个标志来启用/禁用输入打印。在

我学到的是recvline.HistoricCrecvline.CharacterReceived()方法处理来自终端的输入文本,并且终端.写入()用于打印到标准输出。在

相关问题 更多 >

    热门问题