① 如何使用python连接远程Windows服务器

你可以在winodws 上架设ssh 服务器, 然后你就可以在本地通过ssh协议来连接服务器,然后选择程序. python 的ssh 模块可以使用paramiko

② python 怎么开启远程的服务

你可以使用python的pexcpct包通过ssh调用远程服务器指令:
import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
s.sendline ('uptime') # run a command
s.prompt() # match the prompt
print s.before # print everything before the propt.
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)

③ 如何使用python实现远程登录到linux再远程登录到另一个linux

python用parammiko模块实现linux的远程操作:
一、parammiko 的安装
提前下载好需要的软件包。
1、安装pycrypto
$ tar -zxvf pycrypto-2.0.1.tar.gz $ cd pycrypto-2.0.1 $ python setup.py build $ sudo python setup.py install
2、安装paramiko $ tar -zxvf paramiko-1.7.6.tar.gz $ cd paramiko-1.7.6 $ python setup.py build $ sudo python setup.py install
可能遇到的问题及解决:
如果在安装pycrypto2.0.1时发生如下错误
view plain
<strong>[/pycrypto-2.0.1]$ sudo python setup.py build running
build running build_py running build_ext building '
Cryp to.Hash.MD2' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexce
ptions -fstack-protector ——param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -Isrc/ -I/usr/include/pyt
hon2.4 -c src/MD2.c -o build/temp.linux-x86_64-2.4/src/MD2.o
unable to execute gcc: No such file or directory error: comma
nd 'gcc' failed with exit status 1</strong>
解决方案1:
可能是缺少pyton-dev安装包导致
$ yum list | grep python-dev
$ yum -y install python-dev* 「需root权限执行」
执行后,重新安装即可成功。
解决方案2:
如果解决方案1还不能解决问题,可能是“gcc”没有安装或者不再PATH中
$ whereis gcc 「检查gcc」
$ echo $PATH 「检查gcc是否在PATH中」
如果没有安装 “gcc” ,执行如下命令
$ yum list | grep gcc
$ sudo yum install -y gcc.x86_64
执行后,重新安装即可。

④ 关于python远程登录

我的建议
1)用wireshark截包来分析交互进行到哪一步了。也许提示符匹配后就没有成功。
2)注意回车换行,也许没发\n也会导致远程没有执行。

⑤ 如何远程登录Linux机器并运行Python程序

新手对于没有图形界面的linux远程登录及其操作都充满畏惧。这里介绍一个简单的软件。叫作BitViz。简称BV for short。

一、软件安装
这里使用Putty的一个client软件叫作Bv SshClient. 你可以在putty的官网上找到其链接。

Bitvise Tunnelier

Tunnelier is an SSH and SFTP client for Windows. It is developed and supported professionally by Bitvise. Tunnelier is robust, easy to install, easy to use, and supports all features supported by PuTTY, as well as the following:

graphical SFTP file transfer; 图形界面最喜欢
single-click Remote Desktop tunneling;
auto-reconnecting capability;
dynamic port forwarding through an integrated proxy;
an FTP-to-SFTP protocol bridge. 方便的上传下载和删除操作。
Tunnelier is free for personal use, as well as for indivial commercial use inside organizations. You can download Tunnelier here. ownload-area

二、熟悉窗口
下面一个例子,是找到python软件安装位置的演示:
1. 首先,我进入到root

步骤一,进入root

2. 输入/home

步骤二,进入home

3. 点击其中子文件夹,即可找到,方便了。

步骤三,找到python文件夹

三、easy_install python library
Example Of python-setuptools Being Installed:
[root@server ~]# yum install python-setuptools

Yum Command To Install python-setuptools-devel:
[root@server ~]#yum install python-setuptools-devel

在linux 下: 使用方法非常简单,在命令行输入“easy_install 参数”即可。
这比我想象的要方便很多!在windows里,我要cmd-cd & easy_install flickrapi
在ssh的命令窗口,只需输入 easy_install flickrapi

如下图:

easy_install flickrapi

四、run python script as a background process in linux

So, you have a server to which you connect remotely, upload a python script and want to run it and logout from the server keeping the program running. If you frequently work with spiders, you surely want to do it. But how to do it? For example if your script's name is script.py, then the command is:

[root@server ~]# nohup python script.py &

And sometimes you may be interested to see the output is that being generated. Then you should view the nohup.out file! This command can be useful:

[root@server ~]# tail -f nohup.out

看看效果!

⑥ 如何使用python执行远程shell脚本

最近有个需求就是页面上执行shell命令,第一想到的就是os.system,

代码如下:
os.system('cat /proc/cpuinfo')

但是发现页面上打印的命令执行结果 0或者1,当然不满足需求了。

尝试第二种方案 os.popen()

代码如下:
output = os.popen('cat /proc/cpuinfo')
print output.read()

通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出。但是无法读取程序执行的返回值)

尝试第三种方案 commands.getstatusoutput() 一个方法就可以获得到返回值和输出,非常好用。

代码如下:
(status, output) = commands.getstatusoutput('cat /proc/cpuinfo')
print status, output

Python Document 中给的一个例子,

代码如下:
>>> import commands
>>> commands.getstatusoutput('ls /bin/ls')
(0, '/bin/ls')
>>> commands.getstatusoutput('cat /bin/junk')
(256, 'cat: /bin/junk: No such file or directory')
>>> commands.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found')
>>> commands.getoutput('ls /bin/ls')
'/bin/ls'
>>> commands.getstatus('/bin/ls')
'-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls'

⑦ python远程操作windows服务器有什么方案

可以使用python+paramiko。 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远内程服务器的连接。 使用paramiko可以很好容的解决以下问题: 需要使用windows客户端, 远程连接到Linux服务器,查看上面的日志状态,批量配置远程服务器,文件上传,文件下载等 具体可以参考: http://www.paramiko.org/

⑧ 请教各位大神用纯Python能不能编写一个远程控制软件,比如远程控制别人

能,但是很麻烦,需要远程有特定的包。需要的dependency非常大。
完全比不上编译一个exe就完事了。尤其是windows这系统不自带python。

⑨ 如何远程调试Python代码

背景描述
有时候Python应用的代码在本地开发环境运行十分正常,但是放到线上以后却出现了莫名其妙的异常,经过再三排查以后还是找不到问题原因,于是就在想,要是可以在服务器环境中进行单步跟踪调试就好了。
然而,在服务器系统上安装一个IDE肯定是不现实的;通过SSH远程到服务器端,采用pdb进行调试虽然可行,但是操作还是较为繁琐,而且也不够直观。
那么,是否可以将开发环境中的IDE与服务器环境相连,实现利用开发环境的IDE调试服务器环境中运行的程序呢? 答案是肯定的,这就是远程调试(Remote Debug)。
远程调试的工作原理
远程调试的功能在Eclipse、IntelliJ IDEA等大型IDE中均有支持,实现原理都基本相同,这里采用PyCharm进行说明。
在远程调试的模式下,PyCharm(IDE)扮演服务端(Server)的角色,而运行在远程计算机上的应用程序扮演客户端(Client)的角色。正因如此,进行远程调试时,需要先在本地开发环境中设定端口并启动IDE,IDE会对设定的端口开始监听,等待客户端的连接请求;那远程计算机中的应用程序又是怎样与IDE建立通讯连接的呢?
针对远程调试功能,PyCharm提供了pydevd模块,该模块以pycharm-debug.egg的形式存在于PyCharm的安装路径中。远程计算机安装该库文件后,然后就可以调用pydevd.settrace方法,该方法会指定IDE所在机器的IP地址和监听的端口号,用于与IDE建立连接;建立连接后,便可在IDE中对远程在远程计算机中的程序进行单步调试。
远程调试的配置方法
1、在远程计算机上安装pydevd模块
首先,在本地开发环境的PyCharm安装路径中找到pycharm-debug.egg文件(若远程计算机运行的是Python3,则需要pycharm-debug-py3k.egg);
然后,将pycharm-debug.egg文件拷贝至远程计算机,在远程计算机中将pycharm-debug.egg添加至引用路径,可以采用多种方式:
采用easy_install pycharm-debug.egg命令进行安装(pip命令无法安装,只能使用easy_install)
将pycharm-debug.egg添加至PYTHONPATH或sys.path: import sys; sys.path.append('/home/leo/app-dependancies/pycharm-debug.egg')
解压pycharm-debug.egg,将其中的pydev文件夹拷贝至远程应用程序目录下
最后,在远程计算机的Python命令行中输入import pydevd,若没有报错则说明pydevd模块安装成功。
2、在本地开发环境的PyCharm中进行监听配置
在PyCharm中配置说明如下:
【Run】->【Edit Configurations】
【Add New Configuration】->【Python Remote Debug】
填写Local host name和Port,其中Local host name指的是本机开发环境的IP地址,而Port则随便填写一个10000以上的即可;需要注意的是,由于远程计算机需要连接至本地开发环境,因此本地IP地址应该保证远程可以访问得到
【Apply】and【OK】
3、在本地开发环境的PyCharm中配置Mapping映射
4、在远程计算机的应用程序中插入代码
将如下代码插入至远程计算机的应用程序中。
import pydevd
pydevd.settrace('100.84.48.156', port=31235, stdoutToServer=True, stderrToServer=True)

其中,IP地址和端口号要与PyCharm中的监听配置保持一致。
5、在PyCharm中启动Debug Server
【Run】->【Debug…】,选择刚创建的远程调试配置项,在Debug Console中会显示如下信息:
Starting debug server at port 31235
Waiting for process connection...
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('100.84.48.156', port=31235, stdoutToServer=True, stderrToServer=True)

这说明Debug Server已经启动并处于监听状态。
6、在远程计算机中启动应用程序
在远程计算机中启动应用程序,当执行到pydevd.settrace语句时,便会与本地开发环境中的PyCharm建立通讯连接,接下来便可以在本地IDE中进行单步调试了。
需要注意的是,本地开发环境必须保证IP地址和端口号可从远程计算机访问得到,否则会无法建立连接。
$ telnet 100.84.48.156 31235
Trying 100.84.48.156...
telnet: Unable to connect to remote host: Connection refused

$ python devicedectector.py
Could not connect to 100.84.48.156: 31236
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pycharm-debug.egg/pydevd_comm.py", line 478, in StartClient
s.connect((host, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused

⑩ 如何使用python远程登录一个操作系统,并执行某条命令

你可以使用python的pexcpct包通过ssh调用远程服务器指令:
import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
s.sendline ('uptime') # run a command
s.prompt() # match the prompt
print s.before # print everything before the propt.
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)