[关闭]
@myles 2018-08-03T00:40:40.000000Z 字数 515 阅读 658

SSH 连接之 paramiko 模块学习

未分类


学习参考:http://www.ywnds.com/?p=11494

https://www.youtube.com/watch?v=CKVMwte8Z-s

  1. # coding:utf-8
  2. import paramiko
  3. def sshclient():
  4. client = paramiko.SSHClient()
  5. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  6. client.connect(hostname="192.168.31.56", port=22, username="myles", password="toor", timeout=10)
  7. stdin,stdout,stderr = client.exec_command('ifconfig')
  8. client.close()
  9. return stdout
  10. stdout = 1
  11. n = 0
  12. try:
  13. while stdout:
  14. sshclient()
  15. if stdout:
  16. n += 1
  17. print("登录{}成功...".format(n))
  18. except:
  19. print("登录{}次时,测试失败...".format(n))
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注