[Python] 通过python自动连接ssh服务器 →→→→→进入此内容的聊天室

来自 , 2019-06-22, 写在 Python, 查看 96 次.
URL http://www.code666.cn/view/58c58f9c
  1. #!/usr/bin/python
  2.  
  3. #-*- coding:utf-8 -*-
  4.  
  5. import sys, time, os
  6.  
  7. try:
  8.     import pexpect
  9. except ImportError:
  10.     print """
  11.        You must install pexpect module
  12.    """
  13.     sys.exit(1)
  14.  
  15. addr_map = {
  16.     'v3' :('root@192.168.1.162', 'sina@2009'),
  17.     'dev':('test016@192.168.1.136', 'test016'),
  18. }
  19.  
  20. try:
  21.     key = sys.argv[1]
  22.     host = addr_map[key]
  23. except:
  24.     print """
  25.        argv error, use it link
  26.        jssh v3, v3 must defined in addr_map
  27.    """
  28.     sys.exit(1)
  29.  
  30. server = pexpect.spawn('/usr/bin/ssh %s' % host[0])
  31.  
  32. server.expect('.*ssword:')
  33.  
  34. server.sendline(host[1])
  35.  
  36. server.interact()
  37. #//python/5755

回复 "通过python自动连接ssh服务器"

这儿你可以回复上面这条便签

captcha