通过网络在远程计算机上执行命令 [英] Execute Commands on Remote Computers over Network

查看:89
本文介绍了通过网络在远程计算机上执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究这个话题并想出一些代码来使它工作起来。它使用SSL并需要第三方包Paramiko(

需要PyCrypto)。但是,此刻我还没有网络测试代码上的
!尝试连接到localhost(127.0.0.1)失败。在我购买网络组件之前,我想确保这些代码能够正常工作。

有两台网络计算机的人会为我试用吗?谢谢!

代码:


def remote_execute_command(ipaddr,port,user,passwd = None,cmd):

import paramiko

transport = paramiko.Transport(ipaddr +":" + port)

transport.connect(username = user,password = passwd)

channel = transport.open_session()

channel.exec_command(cmd)

print" Command" + cmd +"由用户执行 + user +"用

密码" + passwd +"在 + host +":" +端口

I have been researching this topic and come up with some code to make
it work. It uses SSL and requires the 3rd party package Paramiko (which
requires PyCrypto). However, at this moment I have no network to test
the code on! Trying to connect to localhost (127.0.0.1) fails. Before I
buy network components, I want to be sure that this code will work.
Will someone with two networked computers try it out for me? Thanks!
Code:

def remotely_execute_command(ipaddr, port, user, passwd=None, cmd):
import paramiko
transport = paramiko.Transport(ipaddr + ":" + port)
transport.connect(username=user, password=passwd)
channel = transport.open_session()
channel.exec_command(cmd)
print "Command " + cmd + " executed by user " + user + " with
password " + passwd + " at " + host + ":" + port

推荐答案

文章< 11 ****************** ****@c74g2000cwc.googlegroups .com>,

" dylpkls91" < DP ****** @ pacbell.net>写道:
In article <11**********************@c74g2000cwc.googlegroups .com>,
"dylpkls91" <dp******@pacbell.net> wrote:
我一直在研究这个主题并提出一些代码来使它工作。它使用SSL并需要第三方包Paramiko(它需要PyCrypto)。
I have been researching this topic and come up with some code to make
it work. It uses SSL and requires the 3rd party package Paramiko (which
requires PyCrypto).




为什么不产生SSH的调用?



Why not just spawn an invocation of SSH?




Lawrence D''Oliveiro写道:

Lawrence D''Oliveiro wrote:
文章< 11 ************ **********@c74g2000cwc.googlegroups .com>,
" dylpkls91" < DP ****** @ pacbell.net>写道:
In article <11**********************@c74g2000cwc.googlegroups .com>,
"dylpkls91" <dp******@pacbell.net> wrote:
我一直在研究这个主题并提出一些代码来使它工作。它使用SSL并需要第三方包Paramiko(它需要PyCrypto)。
I have been researching this topic and come up with some code to make
it work. It uses SSL and requires the 3rd party package Paramiko (which
requires PyCrypto).



为什么不生成SSH的调用?



Why not just spawn an invocation of SSH?




@Dennis:是的,我知道,但我没在想,而且它没有解决

问题。


@Lawrence:很抱歉,我是新手。你能解释这个

的含义,以及我如何用Python做到这一点?非常感谢。



@Dennis: yes, I know, but I wasn''t thinking, and it doesn''t solve the
problem.

@Lawrence: I''m sorry, but I''m a newbie. Can you explain what this
means, and how I could do it in Python? Thank you very much.


文章< 11 ********************* *@u72g2000cwu.googlegroups .com> ;,

" dylpkls91" < DP ****** @ pacbell.net>写道:
In article <11**********************@u72g2000cwu.googlegroups .com>,
"dylpkls91" <dp******@pacbell.net> wrote:
Lawrence D''Oliveiro写道:
Lawrence D''Oliveiro wrote:
文章< 11 **************** ****** @ c74g2000cwc.googlegroups .com>,
" dylpkls91" < DP ****** @ pacbell.net>写道:
In article <11**********************@c74g2000cwc.googlegroups .com>,
"dylpkls91" <dp******@pacbell.net> wrote:
>我一直在研究这个主题并想出一些代码来使
>它起作用。它使用SSL并需要第三方软件包Paramiko(
>需要PyCrypto)。
>I have been researching this topic and come up with some code to make
>it work. It uses SSL and requires the 3rd party package Paramiko (which
>requires PyCrypto).



为什么不生成SSH的调用?



Why not just spawn an invocation of SSH?



你能解释一下这意味着什么,以及我如何用Python做到这一点?



Can you explain what this means, and how I could do it in Python?




SSH是在一个* nix上远程执行命令的标准方法

系统来自另一个< http://www.openssh.com/>。它包含在所有

自我尊重的* nix系统中。您可以在两个系统上的特定帐户之间建立信任

关系,因此可以在没有密码的情况下将
连接到另一个系统。所有通信都是加密的

来锁定窃听者。



SSH is the standard means of remotely executing commands on one *nix
system from another <http://www.openssh.com/>. It is included with all
self-respecting *nix systems these days. You can set up a trust
relationship between particular accounts on two systems, so one can
connect to the other without a password. All communication is encrypted
to lock out eavesdroppers.


这篇关于通过网络在远程计算机上执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆