ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='192.168.1.2', port=22, username='cisco', password='cisco')  # 地址是192.168.1.2,用户名/密码都是cisco
client = ssh.invoke_shell()
def run_cmd(cmd, endswith):   # 形参:cmd命令,结束符
    buff = ''
    client.send(cmd)
    while not buff.endswith(endswith):
        resp = str(client.recv(1024), 'utf-8')
        buff += resp
    return buff
res = ''
res += run_cmd('enable\n', 'Password: ')
res += run_cmd('cisco\n', '#')
res += run_cmd('terminal length 0\n', '#')
res += run_cmd('show run\n', '#')
print(res)
ssh.close()

最新文章

  1. FireDAC 超时
  2. rapid js framework
  3. Max retries exceeded with url
  4. BOM(制造数据管理)
  5. Enabling Active Directory Authentication for VMWare Server running on Linux《转载》
  6. oracle数据库10g下载地址
  7. C# @字符用法
  8. Linux文件的复制、删除和移动命令
  9. Linux系统格式化新磁盘并挂载分区
  10. MyBatis-Plugins
  11. kafka其中一台节点坏掉的迁移或者数据迁移
  12. Java代码优化小结(二)
  13. PAT 1031 Hello World for U
  14. crm SDK 设置用户的上级
  15. jquery.cookie介绍和用法
  16. 如何用简单例子讲解 Q - learning 的具体过程?
  17. python xlsxwriter写excel并操作各种格式属性
  18. Microsoft Dynamics CRM 2011 面向Internet部署 (IFD) CRM 登录出现会话超时的解决办法
  19. Linux 用户和文件
  20. Scrapy实战篇(五)爬取京东商城文胸信息

热门文章

  1. python --- 07 补充( join 删除和添加 fromkeys ) 深浅拷贝
  2. topcoder srm 490 div1
  3. VS2015密钥
  4. 一些常用的mysql语句实例-以后照写
  5. 弄懂linux shell对包含$的变量的执行过程?
  6. 二进制枚举例题|poj1222,poj3279,poj1753
  7. [java变量] - 字符串数组转long型数组
  8. 51nod 1052 最大M子段和
  9. 1st,Python基础——01
  10. linux golang