python3的RDP库 [英] RDP library for python3
问题描述
我需要一个 python3 RDP 库.我找到了 https://github.com/citronneur/rdpy,但我不明白如何我可以使用端口、登录名和密码连接到主机吗?此代码中没有登录名和密码:
I need a python3 RDP library. I have found https://github.com/citronneur/rdpy, but I don't understand how can I connect to host with port, login and password. There is no login and password in this code:
from rdpy.protocol.rdp import rdp
from twisted.internet import reactor
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)
reactor.connectTCP(ip, port, MyRDPFactory())
reactor.run()
也许,当我已经连接到主机时,我需要在登录表单中输入登录名和密码?我该怎么做?
Maybe, I need to input login and password in login form when I am already connected to host? How can I do it?
推荐答案
目前没有用于 RDPY
的 Python 3 实现.这是一个带有用户名和密码的版本.您可以简单地在构建函数中将这些信息设置到控制器中.
At the moment there is no Python 3 implementation for RDPY
. Here's a version with username and password. You can simply set these informations to the controller in the build function.
from rdpy.protocol.rdp import rdp
from twisted.internet import reactor
class MyRDPFactory(rdp.ClientFactory):
def __init__(self, username, password,domain):
self._username = username
self._password = password
self._domain = domain
self._security = rdp.SecurityLevel.RDP_LEVEL_SSL
def clientConnectionLost(self, connector, reason):
print reason
reactor.stop()
def clientConnectionFailed(self, connector, reason):
print 'connection failed'
reactor.stop()
def buildObserver(self, controller, addr):
controller.setUsername(self._username)
controller.setPassword(self._password)
controller.setDomain(self._domain)
class MyObserver(rdp.RDPClientObserver):
def onReady(self):
"""
@summary: Call when stack is ready
"""
# send 'r' key
self._controller.sendKeyEventUnicode(ord(unicode("r", 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)
reactor.connectTCP("XXX.XXX.XXX.XXX", 3389, MyRDPFactory(username='Please',domain='Dont Hack',password='Me'))
reactor.run()
这篇关于python3的RDP库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!