使用 Paramiko / Twisted 模拟交互式 SSH 客户端

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

我需要模拟 SSH 客户端并记录输入的命令。

我遵循了不同的链接,但大多数示例都与自动化任务相关。出于测试目的,我需要模拟 Interative SSH 会话和 log 命令。

注意:Paramiko 不是强制性的。非常感谢扭曲的资源

python ssh twisted paramiko twisted.conch
1个回答
0
投票

使用

Channel.get_pty
Channel.invoke_shell
模拟交互式 SSH 终端会话。

sshClient = paramiko.SSHClient()
sshClient.connect(host, username=user, password=pass)
channel = sshClient.get_transport().open_session()

# Open interactive SSH session
channel.get_pty()
channel.invoke_shell()

print('Executing command 1')    
channel.send('command 1\n')

print('Executing command 2')
channel.send('command 2\n')
© www.soinside.com 2019 - 2024. All rights reserved.