Paramiko Emulating IBM 3151.我如何发送正确的控制按键
问题描述:
我使用Python 2.7 Paramiko SSH进入一个使用IBM 3151 keymapping的非常旧的系统。当时的键盘有一个用于提交响应的输入或“发送”键。在Secure NetTerm中,我可以访问此系统,“发送”键映射到键盘上的右侧Ctrl键。在我的生活中,我无法弄清楚如何通过Paramiko将“发送”键发送到终端。以下是我的测试代码。我能够通过接受\ n的前几个菜单选项来完成,但我正在进入一个需要“发送”键的“弹出”屏幕。按下右侧的ctrl键在模拟器中工作,但我似乎无法得到任何东西在Paramiko工作。任何帮助,将不胜感激。Paramiko Emulating IBM 3151.我如何发送正确的控制按键
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect('some_server.com', port=22,username='some_user', password='some_password')
except paramiko.SSHException:
print "Connection Failed"
quit()
channel = ssh.invoke_shell(term='IBM-3151', width=80, height=24, width_pixels=0, height_pixels=0)
channel_data = str()
host = str()
srcfile = str()
while True:
if channel.recv_ready():
channel_data += channel.recv(9999)
else:
continue
print channel_data
#Go to store
if channel_data.endswith('> '):# in channel_data:
channel.send('5\n')
# Select a store
if channel_data.endswith(' : '): # in channel_data:
channel.send('0330\n')
if channel_data.endswith('): '): # in channel_data:
channel.send('Y\n')
if 'PRESS SEND TO CONTINUE....' in str(channel_data):
print 'test1' # if statement works
time.sleep(5)
channel.send('^[!l^M') # tried all kinds of stuff here
print 'test2' # script passes to here with no errors.
答
我会确定哪些字符实际上是由发送发送通过
- 捕获所有的字符(或输入)键从使用
script
会话AIX系统(可能需要此分析) - 在AIX系统的shell中,使用
cat
(回声)并按控制 -V按*前输入。
这样做与工作终端当然。如果cat
所示的数据不适用于您的脚本,则可能是已完成一些初始化,例如,将Secure NetTerm置于应用程序模式。