我正在尝试使用MockSSH设置一个模拟shell服务器。
为了测试我所处理的特定应用程序,我需要能够阻止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"'!默认情况下禁用回波,或者在发出'stty -echo‘命令时也会正常工作。
发布于 2015-08-02 19:22:00
经过几天的工作后,我找到了一个适合我的解决方案,注释掉了SSHProtocol实现的characterReceived方法中的“characterReceived(Ch)”,完全禁用了输入打印,好像'stty -echo‘命令是在bash中运行的。
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.HistoricRecvLine.characterRecieved()方法处理来自终端的输入文本,terminal.write()用于打印到STDOUT。
https://stackoverflow.com/questions/31767132
复制相似问题