Python网络设备..一般查询:

时间:2011-08-22 16:07:08

标签: python networking network-programming cisco-ios

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

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

  1. 要求按Ctrl-y继续并使用箭头键列出选项“硬件信息”,我需要选择n输入以获取信息。
  2. 如何编写脚本以进入完全键盘驱动的北电设备..如ctrl-y ctrl x,使用箭头键等

1 个答案:

答案 0 :(得分: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.

您只需查找控件等键的特殊控制代码即可。