Python实现SSH

pyssh:Python SSH 网关 pyssh Python SSH 网关 立即下载

SSH(Secure Shell)

安全外壳协议,是建立在应用层基础上的安全协议。

paramiko

安装

conda install paramiko 或 pip3 install paramiko

基本操作

import paramiko
from conf import *

# 创建ssh客户端对象
client = paramiko.SSHClient()
try:
    # 首次ssh远程时会提示输入yes或no
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # 远程连接
    client.connect(hostname, port, username, password, timeout=20)
    # 执行命令
    stdin, stdout, stderr = client.exec_command('pwd')
    # 获取命令执行结果,返回list
    print(stdout.readlines())
except Exception as e:
    print('\033[031m{}\033[0m'.format(e))
# 关闭
client.close()
print
[’/root\n’]

写成类

import paramiko
from conf import *


class SSH:
    def __init__(self):
        self.c = paramiko.SSHClient()
        self.c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.c.connect(hostname, port, username, password, timeout=20)

    def __del__(self):
        self.c.close()
        print('\033[033m关闭SSH\033[0m')

    def exec_cmd(self, command, print2=True):
        stdin, stdout, stderr = self.c.exec_command(command)
        if print2:
            print('\033[036m{}\033[0m'.format(stdout.readlines()))
            print('\033[031m{}\033[0m'.format(stderr.readlines()))


if __name__ == '__main__':
    c = SSH()
    c.exec_cmd('abcd')  # 执行一条不存在的指令
    c.exec_cmd('ls /home/hjw')
    c.exec_cmd('mkdir /home/hjw/a', False)  # 创建文件夹a
    c.exec_cmd('ls /home/hjw')
    c.exec_cmd('rmdir /home/hjw/a', False)  # 删除文件夹a
    c.exec_cmd('ls /home/hjw')

「Unity3D」Addressable版本冲突解析:SBP与Addressables兼容性问题实战指南 本文深入解析Unity3D中Addressable与SBP(Scriptable Build Pipeline)版本冲突问题,提供实战解决方案。当遇到「Build Task CreateBuiltInShadersBundle failed」错误时,可通过版本匹配、临时资源引用或构建参数调整解决。文章详细分析兼容性原理,并给出版本组合指南与最佳实践,帮助开发者高效处理资源构建问题。 阅读详情

相关推荐

逆向拆解dy接口a_bogus 1.0.1.19版本核心算法(纯算版)第二部分

本文深入解析了dy接口a_bogus 1.0.1.19版本的核心算法,重点介绍了逆向分析的基础方法论、魔改Base64编码识别与还原、随机数生成与位运算解析等关键技术。通过详细的代码示例和实用技巧,帮助开发者掌握逆向工程中的关键步骤,特别是针对a_bogus参数的生成逻辑和混淆处理。

weixin_29288313的博客 411

基于PyQt5的图形化界面开发——自制ssh工具

基于PyQt5的图形化界面开发——自制ssh工具

qq_53381910的博客 2980

保姆级教程:用Docker一键部署vLLM大模型推理服务(附常见报错解决方案)

本文提供了一份详细的Docker化vLLM大模型推理服务部署指南,涵盖从环境准备到性能调优的全流程。通过容器化技术解决大语言模型部署中的显存利用率、吞吐量等核心问题,并附常见报错解决方案,帮助开发者快速构建高效、可扩展的AI推理服务。

weixin_29248313的博客 494

了解这几个python工具库运维自动化提效一倍

当谈到在Python中进行SSH操作时,有几个知名的工具包可供选择。它们提供了便捷的API和功能,使得与远程服务器进行安全连接和执行命令变得更加容易。在本篇博客中,我们将介绍以下几个Python中出名的SSH工具库:Paramiko、Fabric、和PySsh。

m0_59162248的博客 982

六轴机械臂正逆解计算

机械臂运动学就是。包括(Forward Kinematics)和(InverseKinematics)两部分。正运动学就是逆运动学则是关节变量->机械臂末端执行器的姿势=正向运动学机械臂未端执行器的位姿->关节变量=逆向运动学。

gaoxiaochan的博客 1万+

AMBA VIP基础使用方式(AXI)

AXI环境配置 1)基础配置 作为master或者slave使用时,对应的is_active = 1 只作为i监测(monitor)使用时,对应slave_cfg的is_active = 0(对应端口连接也有所区别) class smu_axi_cfg extends svt_axi_system_configuration; `uvm_object_utils(smu_aix_cfg) function new(string name="smu_axi_cfg); super.new(n..

qq_37573794的博客 7984

使用PARAMIKO PYQT实现的SSH远程批量管理工具

如果存在大量的远程主机需要管理,而且,操作内容是一致的,用脚本的方式实现是可行的,然而脚本方式却不是那么灵活,并且状态也不是很直观.以前使用python+qt+paramiko实现的一个批量管理ssh主机的工具,可以实现日常的批量管理,支持密钥验证,支持批量传送文件,暂不支持交互式命令.欢迎有兴趣的朋友研究,本人xgtiger保留所有权利(包括免责权),谢谢理解.编译环境版本...

weixin_34128237的博客 551

window系统 dlib库安装

1. 安装visual studio 1.1. 安装vs2017或以上版本 1.2. 我们需要安装使用C++的桌面开发,且必须选上用于Cmake的Visual C++工具 1.3. 安装完成后,将D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin 添加到环境变量PATH中 2 下载cmake文件,并添加环境变量 2.1 在c

@bangbang的博客 818

ssh工具paramiko pyqt工具

ssh工具 pyqt

jacke121的专栏 1651

MOSFET开关损耗全面讲解:从原理到优化策略

深入剖析MOSFET开关损耗的产生机制,结合实际应用场景,讲解如何通过驱动设计和电路优化降低损耗,提升系统效率。重点关注mosfet在高频开关下的表现与热管理。

weixin_29476595的博客 1061

使用STM32实现简单的语音识别

此外,还需要将计算机的音频输出连接到外部音频放大器上,以便将测试语音播放到MAX9814麦克风模块。运行STM32代码后,系统将开始采集语音数据,并在采集完成后调用Python脚本进行MFCC特征提取。在本案例中,我们将使用STM32F4开发板、MAX9814麦克风模块和MFCC特征提取算法来实现语音识别。通过这个案例,我们可以了解到如何结合STM32开发板和Python实现语音识别,并可以根据需要进行相关扩展和优化。现在,我们可以编译和烧录STM32代码到开发板中,并准备好测试语音文件。

吃不胖. 1475

Python进行ssh操作

python进行ssh操作需要用到paramiko模块,paramiko是python的三方ssh模块,通过socket实现了ssh功能。 下载paramiko pip install paramiko paramiko使用代码示例如下 import paramiko #创建一个ssh的客户端,用来连接服务器 ssh = paramiko.SSHClient() #创建一个ss...

qq_39112101的博客 3万+

【北大核心-代码复现】基于 VMD-FFCM-iTransformer 光伏功率短期预测

【北大核心-代码复现】基于 VMD-FFCM-iTransformer 光伏功率短期预测

769

python ssh实现_Python之——实现SSH隧道功能

试想在如下环境中:你可以访问一台在内网中的SSH服务器,同时,你还想访问在同一个网段中的Web服务器。你不能直接访问Web服务器,但是SSH服务器可以访问Web服务器,而且这个SSH服务器上没有安装你想要使用的工具。我们可以利用Python创建一个转发的SSH隧道来实现这些功能,具体详情参见如下代码:# -*- coding:UTF-8 -*-'''文件可将SSH服务端打开的某个端口的数据流量导向...

weixin_39709178的博客 915

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python ssh实现_Python实现建立SSH连接的方法

本文实例讲述了Python实现建立SSH连接的方法。分享给大家供大家参考。具体实现方法如下:我需要实现一个Windows下远程连接到SSH服务器执行命令的功能,所以就在网上找资料。我的环境是:Windows7 64位,Python 2.7 32位。按照网上的说法,需要下载pycrypto和paramiko两个模块进行安装。最后下载的版本是pycrypto2.3和paramiko1.7.6。安装过程...

weixin_36474001的博客 732

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Python中实现SSH功能

是一个Python实现的SSHv2协议,提供了客户端和服务器功能。在Python中实现SSH功能,通常会使用。请根据实际情况替换示例代码中的。

scoone的博客 1068

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

python ssh实现_python实现SSH 转发

#-*- coding: utf-8 -*-from socket import *importthreadingimportQueue#test in python 2.7#a list of local port mapped to machinessh_server_list = [{"host": '10.239.58.102', "port": 8102, "ip": "192.168....

weixin_39655689的博客 269

python实现ssh登录_使用python 实现自动登录ssh

介绍本文介绍使用python 自动连ssh,并通过正则处理返回值。通过这段代码,可以使一些繁杂的工作,变成比较简单以及自动化。代码#!/usr/bin/env pythonimport pexpectimport signal, fcntl, termios, struct, sysglobal_pexpect_instance = None# 当窗口大小有改变时def sigwinch_pass...

weixin_33331559的博客 2675

Python实现ssh登录

转载自:http://www.cnblogs.com/whatisfantasy/p/6138663.html python下的ssh都需要借助第三方模块paramiko来实现,在使用前需要手动安装。 一、python实现ssh (1) linux下的ssh登录 root@ubuntu:~# ssh morra@192.168.1.42 The authenti

wayhome95的博客 2961

python使用paramiko实现SSH的应用

Paramiko是Python编程语言的一个SSH客户端。它在Python中实现了SSHv2协议,支持使用加密和认证的方式登录SSH服务器、上传和下载文件,以及执行SSH命令等功能。本文记录实验:在python下调用paramiko实现ssh功能后,出错和恢复。

gongdiwudu的专栏 1万+

使用Python脚本实现SSH登录设备

正文共:1111 字 9 图,预估阅读时间:6 分钟如果没有自动化的管理工具,我们管理设备还要一台一台的去查看;有了自动化之后,理论上这个问题能得到极大改善。前面我们介绍了Python的安装(如何使用Python提取Excel中固定单元格的内容),以及如何通过Python读取EXCEL的数据(使用Python批量处理Excel的内容),那能不能使用Python来实现设备的自动化管理呢?我们今天来试...

衡水铁头哥的博客 1773

Python实现ssh自动连接

此文章为了实现不同PC端可以通过Python代码来代替终端命令实现ssh连接。

Yf18005429102的博客 1163

Python使用Paramiko实现SSH管理

paramiko 是一个用于在Python中实现SSHv2协议的库,它支持对远程服务器进行加密的通信。目前该模块支持所有平台架构且自身遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接,你可以在Python中实现SSH客户端和服务器,并进行安全的文件传输和远程命令执行。

微软技术分享 1万+

python ssh 远程登录,python paramiko实现ssh远程登录

Robinjack 说:wooden kitchen cabinets are perfect your your home, they look good and can be cleaned easily., The Linq Floor PlanRobinjack 说:I love it! am going to share your post to my friends, keep pos...

weixin_33340674的博客 502

python pexpect ssh_python与pexpect实现ssh操作

下载并安装pexpect与ptyprocess模块并结合python2.7实现如下操作tar -zxvf pexpect-4.0.1.tar.gzcd pexpect-4.0.1python setup.py installtar -zxvf ptyprocess-0.5.tar.gzcd /ptyprocess-0.5python setup.py installPy脚本#!/usr/bin/e...

weixin_39754915的博客 183

python实现ssh

首先呢,学习了怎么修改路由器配置,添加guest 百度一下:路由器配置命令 对着敲着玩,就知道应该怎么弄了 然后是重点,实现ssh连接 各种模板网上是有的,我想要解决的问题是:如何将原来屏幕的消息保存到文件之中 涉及到两个问题: 1.child.before存储的是上一次命令所返回的信息 2.很多命令的输出信息在一页之内显示不完全,所以呢,需要按几次空格 试了很多次想了一种

ACdream 1506
上一篇: 爬虫保存图文(按序)
下一篇: PyTorch学习
小基基o_O
博客等级 码龄9年 4414粉丝 467原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小基基o_O

您的鼓励是我创作的巨大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值