0

这个工作: 我曾经为Cisco供应商编写设备驱动程序。我通过 Telnet 设备 IP 使用 putty 登录到那里的设备,它进入设备并在我的脚本中使用一些命令来获取信息 .. 比如我脚本中的 show version 命令n 让我将所有信息读入 CSV 文件。

以下问题的解决方案 现在我们有了一个名为NORTEL的新供应商.. 当我在 putty 中使用 IP 时,它会进入完成菜单或键盘驱动的设备。

  1. 它要求按 Ctrl-y 继续,并使用箭头键列出“硬件信息”等选项列表,我需要选择 n 输入以获取信息。

我如何编写脚本以输入完全是键盘驱动器的北电设备 .. 像 ctrl-y ctrl x ,使用箭头键等

4

1 回答 1

3

使用pexpect。它是一个设计用于与本地或远程进程交互的 python 模块。这是其网站上的一个示例,展示了如何使用它连接到键盘驱动的 FTP 子进程。

   import pexpect
   child = pexpect.spawn ('ftp ftp.openbsd.org')
   child.expect ('Name .*: ')
   child.sendline ('anonymous')
   child.expect ('Password:')
   child.sendline ('noah@example.com')
   child.expect ('ftp> ')
   child.sendline ('ls /pub/OpenBSD/')
   child.expect ('ftp> ')
   print child.before   # Print the result of the ls command.
   child.interact()     # Give control of the child to the user.

您所需要的只是查找诸如控制之类的键的特殊控制代码。

于 2011-08-22T16:13:52.970 回答