code
# coding=utf-8
import paramiko, getpass, sys, traceback
class SSHUtils():
def login(self, ip, port, username, passwd):
self.ip = ip
self.port = port
self.username = username
self.passwd = passwd
def ssh(self, shell):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.ip, self.port, self.username, self.passwd)
stdin, stdout, stderr = ssh.exec_command(shell)
res = stdout.readlines()
ssh.close()
return res
except:
type, value, tb = sys.exc_info()
return traceback.format_exception(type, value, tb)
if __name__ == '__main__':
myssh = SSHUtils()
myssh.login("192.168.12.1", 22, "nio4444", "nio4444")