Python 3.x--paramiko模块详解

一、使用paramiko模块实现SSH功能

下列代码在Windows上运行,连接虚拟机中centos系统。

import paramiko

# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件上的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname="192.168.0.99", port=22, username="root", password="rootroot")
# 执行命令
stdin, stdout, stderr = ssh.exec_command(‘df‘)
# 获取结果
result = stdout.read().decode()
# 获取错误提示(stdout、stderr只会输出其中一个)
err = stderr.read()
# 关闭连接
ssh.close()
print(stdin, result, err)

注:如果注释“ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())”这句,会报错。

时间: 2024-08-26 13:01:46

Python 3.x--paramiko模块详解的相关文章

python里面的xlrd模块详解(一)

那我就一下面积个问题对xlrd模块进行学习一下: 1.什么是xlrd模块? 2.为什么使用xlrd模块? 3.怎样使用xlrd模块? 1.什么是xlrd模块? ?python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库. 今天就先来说一下xlrd模块: 一.安装xlrd模块 ? 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. ?或者在cmd窗口  pip

python里面的xlrd模块详解

1.什么是xlrd模块? 2.为什么使用xlrd模块? 3.怎样使用xlrd模块? 1.什么是xlrd模块? ?python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库. 今天就先来说一下xlrd模块: 一.安装xlrd模块 ? 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. ?或者在cmd窗口  pip install  xlrd 二.使用介绍 1.常

Python学习之String模块详解

本文和大家分享的主要是python 中String 模块相关内容,一起来看看吧,希望对大家 学习python有所帮助. String 模块包含大量实用常量和类,以及一些过时的遗留功能,并还可用作字符串操作. 1. 常用方法 str.capitalize() 把字符串的首字母大写 str.center(width) 将原字符串用空格填充成一个长度为 width 的字符串,原字符串内容居中 str.count(s) 返回字符串 s 在 str 中出现的次数 str.decode(encoding='

Python自学笔记-logging模块详解

简单将日志打印到屏幕: import logging logging.debug('debug message') logging.info('info message') logging.warning('warning message') logging.error('error message') logging.critical('critical message') 输出结果为: WARNING:root:warning message ERROR:root:error message

Python 单向队列Queue模块详解

单向队列Queue,先进先出 '''A multi-producer, multi-consumer queue.''' try: import threading except ImportError: import dummy_threading as threading from collections import deque from heapq import heappush, heappop from time import monotonic as time __all__ =

python多线程之 threading模块详解

1.threading.Thread对象[创建线程的主要对象]: 方法:start():启动线程   run():启动线程后自动调用的方法 join([timeout]):等待到被调用的线程终止   is_alive():返回线程活动状态 属性:name:线程名   ident:线程ID号   daemon:后台标志 2.创建线程的方法: 1:实例化threading.Thread对象 ths = threading.Thread( target = None, name = None, arg

Python中time模块详解

在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主要调用C库,所以各个平台可能有所不同. UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时间.在中国为UTC+8.DST

python中threading模块详解(一)

python中threading模块详解(一) 来源 http://blog.chinaunix.net/uid-27571599-id-3484048.html threading提供了一个比thread模块更高层的API来提供线程的并发性.这些线程并发运行并共享内存. 下面来看threading模块的具体用法: 一.Thread的使用 目标函数可以实例化一个Thread对象,每个Thread对象代表着一个线程,可以通过start()方法,开始运行. 这里对使用多线程并发,和不适用多线程并发做

python的logging模块详解

日志级别 >>>import logging >>>logging.NOTSET 0 >>>logging.DEBUG 10 >>>logging.INFO 20 >>>logging.WARN 30 >>>logging.ERROR 40 >>>logging.CRITICAL 50 >>>logging._levelNames {0:'NOTSET', 10:

(转)python time模块和datetime模块详解

python time模块和datetime模块详解 原文:http://www.cnblogs.com/tkqasn/p/6001134.html 一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共有九个元素组. c.format time 格式化时间,已格式化的结构使时间更具可读性.包括自定义格式和固定格式. 1.时间格式转换图: 2.主要ti