无法通过python连接到rdp

时间:2016-06-30 18:34:17

标签: python linux wmi rdp

我想创建连接到RDP并执行cmd的python脚本,但是我遇到了一些问题:

ImportError: No module named win32com.client

我已经安装了WMI但是我找不到任何在linux下安装win32com.client模块的解决方案,这是我的代码

import win32com.client
conn = wmi.WMI('172.20.23.45', user='Administrator', password='Pass@123')
conn.Win32_Process.Create(CommandLine='mkdir temp')

1 个答案:

答案 0 :(得分:0)

我建议尝试rdpy,因为它是RDP协议的纯Python实现。

以下是自述文件中的示例:

简单RDP客户端

from rdpy.protocol.rdp import rdp

class MyRDPFactory(rdp.ClientFactory):

    def clientConnectionLost(self, connector, reason):
        reactor.stop()

    def clientConnectionFailed(self, connector, reason):
        reactor.stop()

    def buildObserver(self, controller, addr):

        class MyObserver(rdp.RDPClientObserver):

            def onReady(self):
                """
                @summary: Call when stack is ready
                """
                #send 'r' key
                self._controller.sendKeyEventUnicode(ord(unicode("r".toUtf8(), encoding="UTF-8")), True)
                #mouse move and click at pixel 200x200
                self._controller.sendPointerEvent(200, 200, 1, true)

            def onUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
                """
                @summary: Notify bitmap update
                @param destLeft: xmin position
                @param destTop: ymin position
                @param destRight: xmax position because RDP can send bitmap with padding
                @param destBottom: ymax position because RDP can send bitmap with padding
                @param width: width of bitmap
                @param height: height of bitmap
                @param bitsPerPixel: number of bit per pixel
                @param isCompress: use RLE compression
                @param data: bitmap data
                """

            def onSessionReady(self):
                """
                @summary: Windows session is ready
                """

            def onClose(self):
                """
                @summary: Call when stack is close
                """

        return MyObserver(controller)

from twisted.internet import reactor
reactor.connectTCP("XXX.XXX.XXX.XXX", 3389, MyRDPFactory())
reactor.run()