Python第三方库paramiko SSH连接
#!/usr/bin/env python#-*- coding=utf-8 -*-
#说明:基于用户名和密码的transport方式登录
import paramiko
try:
trans = paramiko.Transport(("192.168.58.136",22))
trans.connect(username="root",password="111111")
ssh = paramiko.SSHClient()
ssh._transport = trans
stdin,stdout,stderr = ssh.exec_command("ifconfig")
print (stdout.read().decode().rstrip())
trans.close()
exceptparamiko.SSHException:
print "操作失败!"
页:
[1]