python 安装使用paramiko

来源:互联网 发布:测试bpm软件 编辑:程序博客网 时间:2024/04/30 01:47

1、直接通过pip安装,我测试机上已安装python2.7版本

pip install pycrypto

pip install paramiko


2、测试代码如下ssh_test.py


#!/usr/bin/env python#_*_ coding: utf-8 _*_import paramikocmd=raw_input("输入命令 :")ssh=paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect("192.168.1.254",22,"root","123456")chan=ssh.invoke_shell()chan.settimeout(60)chan.send(cmd + ' ; exit \r')while True:    chandata=chan.recv(1024).decode('UTF-8')    if len(chandata) == 0:                break    print chandatassh.close()




0 0