Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
894dc44a52 | ||
|
|
47dba5bb6e | ||
|
|
c4d071a2e0 | ||
|
|
44d99eaca4 | ||
|
|
9419bea9b0 | ||
|
|
bd91093617 |
@@ -19,9 +19,10 @@ sudo apt-get install python-qt4
|
|||||||
|
|
||||||
#### Windows
|
#### Windows
|
||||||
|
|
||||||
[PyQt4](http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.3/PyQt4-4.11.3-gpl-Py2.7-Qt4.8.6-x32.exe)
|
x86 | x86_64
|
||||||
|
----|-------
|
||||||
[PyWin32](http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win32-py2.7.exe/download)
|
[PyQt4 x86](http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.3/PyQt4-4.11.3-gpl-Py2.7-Qt4.8.6-x32.exe) | [PyQt4 x86_64](http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.3/PyQt4-4.11.3-gpl-Py2.7-Qt4.8.6-x64.exe/download)
|
||||||
|
[PyWin32 x86](http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win32-py2.7.exe/download) | [PyWin32 x86_64](http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win-amd64-py2.7.exe/download)
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
|
|
||||||
|
|||||||
@@ -118,14 +118,15 @@ def autoDetectKeyboardLayout():
|
|||||||
return "fr"
|
return "fr"
|
||||||
elif os.name == 'nt':
|
elif os.name == 'nt':
|
||||||
import win32api, win32con, win32process
|
import win32api, win32con, win32process
|
||||||
import ctypes.windll.user32 as user32
|
from ctypes import windll
|
||||||
w = user32.GetForegroundWindow()
|
w = windll.user32.GetForegroundWindow()
|
||||||
tid = user32.GetWindowThreadProcessId(w, 0)
|
tid = windll.user32.GetWindowThreadProcessId(w, 0)
|
||||||
result = user32.GetKeyboardLayout(tid)
|
result = windll.user32.GetKeyboardLayout(tid)
|
||||||
if result == 0x409409:
|
log.info(result)
|
||||||
|
if result == 0x40c040c:
|
||||||
return "fr"
|
return "fr"
|
||||||
except:
|
except Exception as e:
|
||||||
log.info("failed to auto detect keyboard layout")
|
log.info("failed to auto detect keyboard layout " + str(e))
|
||||||
pass
|
pass
|
||||||
return "en"
|
return "en"
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class RDPScreenShotFactory(rdp.ClientFactory):
|
|||||||
"""
|
"""
|
||||||
@summary: Factory for screenshot exemple
|
@summary: Factory for screenshot exemple
|
||||||
"""
|
"""
|
||||||
|
__INSTANCE__ = 0
|
||||||
def __init__(self, width, height, path, timeout):
|
def __init__(self, width, height, path, timeout):
|
||||||
"""
|
"""
|
||||||
@param width: width of screen
|
@param width: width of screen
|
||||||
@@ -45,6 +46,7 @@ class RDPScreenShotFactory(rdp.ClientFactory):
|
|||||||
@param path: path of output screenshot
|
@param path: path of output screenshot
|
||||||
@param timeout: close connection after timeout s without any updating
|
@param timeout: close connection after timeout s without any updating
|
||||||
"""
|
"""
|
||||||
|
RDPScreenShotFactory.__INSTANCE__ += 1
|
||||||
self._width = width
|
self._width = width
|
||||||
self._height = height
|
self._height = height
|
||||||
self._path = path
|
self._path = path
|
||||||
@@ -57,8 +59,10 @@ class RDPScreenShotFactory(rdp.ClientFactory):
|
|||||||
@param reason: str use to advertise reason of lost connection
|
@param reason: str use to advertise reason of lost connection
|
||||||
"""
|
"""
|
||||||
log.info("connection lost : %s"%reason)
|
log.info("connection lost : %s"%reason)
|
||||||
reactor.stop()
|
RDPScreenShotFactory.__INSTANCE__ -= 1
|
||||||
app.exit()
|
if(RDPScreenShotFactory.__INSTANCE__ == 0):
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
"""
|
"""
|
||||||
@@ -66,9 +70,11 @@ class RDPScreenShotFactory(rdp.ClientFactory):
|
|||||||
@param connector: twisted connector use for rdp connection (use reconnect to restart connection)
|
@param connector: twisted connector use for rdp connection (use reconnect to restart connection)
|
||||||
@param reason: str use to advertise reason of lost connection
|
@param reason: str use to advertise reason of lost connection
|
||||||
"""
|
"""
|
||||||
log.info("connection failes : %s"%reason)
|
log.info("connection failed : %s"%reason)
|
||||||
reactor.stop()
|
RDPScreenShotFactory.__INSTANCE__ -= 1
|
||||||
app.exit()
|
if(RDPScreenShotFactory.__INSTANCE__ == 0):
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
|
|
||||||
def buildObserver(self, controller, addr):
|
def buildObserver(self, controller, addr):
|
||||||
@@ -93,19 +99,20 @@ class RDPScreenShotFactory(rdp.ClientFactory):
|
|||||||
controller.setScreen(width, height);
|
controller.setScreen(width, height);
|
||||||
self._buffer = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32)
|
self._buffer = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32)
|
||||||
self._path = path
|
self._path = path
|
||||||
self._hasUpdated = True
|
self._timeout = timeout
|
||||||
self._brandWidthTask = task.LoopingCall(self.checkUpdate)
|
self._startTimeout = False
|
||||||
self._brandWidthTask.start(timeout) # call every second
|
|
||||||
|
|
||||||
def onUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
|
def onUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
|
||||||
"""
|
"""
|
||||||
@summary: callback use when bitmap is received
|
@summary: callback use when bitmap is received
|
||||||
"""
|
"""
|
||||||
self._hasUpdated = True
|
|
||||||
image = RDPBitmapToQtImage(destLeft, width, height, bitsPerPixel, isCompress, data);
|
image = RDPBitmapToQtImage(destLeft, width, height, bitsPerPixel, isCompress, data);
|
||||||
with QtGui.QPainter(self._buffer) as qp:
|
with QtGui.QPainter(self._buffer) as qp:
|
||||||
#draw image
|
#draw image
|
||||||
qp.drawImage(destLeft, destTop, image, 0, 0, destRight - destLeft + 1, destBottom - destTop + 1)
|
qp.drawImage(destLeft, destTop, image, 0, 0, destRight - destLeft + 1, destBottom - destTop + 1)
|
||||||
|
if not self._startTimeout:
|
||||||
|
self._startTimeout = False
|
||||||
|
reactor.callLater(self._timeout, self.checkUpdate)
|
||||||
|
|
||||||
def onReady(self):
|
def onReady(self):
|
||||||
"""
|
"""
|
||||||
@@ -121,11 +128,7 @@ class RDPScreenShotFactory(rdp.ClientFactory):
|
|||||||
self._buffer.save(self._path)
|
self._buffer.save(self._path)
|
||||||
|
|
||||||
def checkUpdate(self):
|
def checkUpdate(self):
|
||||||
if not self._hasUpdated:
|
self._controller.close();
|
||||||
log.info("close connection on timeout without updating orders")
|
|
||||||
self._controller.close();
|
|
||||||
return
|
|
||||||
self._hasUpdated = False
|
|
||||||
|
|
||||||
return ScreenShotObserver(controller, self._width, self._height, self._path, self._timeout)
|
return ScreenShotObserver(controller, self._width, self._height, self._path, self._timeout)
|
||||||
|
|
||||||
@@ -140,8 +143,8 @@ if __name__ == '__main__':
|
|||||||
#default script argument
|
#default script argument
|
||||||
width = 1024
|
width = 1024
|
||||||
height = 800
|
height = 800
|
||||||
path = "/tmp/rdpy-rdpscreenshot.jpg"
|
path = "/tmp/"
|
||||||
timeout = 2.0
|
timeout = 5.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "hw:l:o:t:")
|
opts, args = getopt.getopt(sys.argv[1:], "hw:l:o:t:")
|
||||||
@@ -159,12 +162,7 @@ if __name__ == '__main__':
|
|||||||
path = arg
|
path = arg
|
||||||
elif opt == "-t":
|
elif opt == "-t":
|
||||||
timeout = float(arg)
|
timeout = float(arg)
|
||||||
|
|
||||||
if ':' in args[0]:
|
|
||||||
ip, port = args[0].split(':')
|
|
||||||
else:
|
|
||||||
ip, port = args[0], "3389"
|
|
||||||
|
|
||||||
#create application
|
#create application
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
|
||||||
@@ -173,6 +171,14 @@ if __name__ == '__main__':
|
|||||||
qt4reactor.install()
|
qt4reactor.install()
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
reactor.connectTCP(ip, int(port), RDPScreenShotFactory(width, height, path, timeout))
|
|
||||||
|
for arg in args:
|
||||||
|
if ':' in arg:
|
||||||
|
ip, port = arg.split(':')
|
||||||
|
else:
|
||||||
|
ip, port = arg, "3389"
|
||||||
|
|
||||||
|
reactor.connectTCP(ip, int(port), RDPScreenShotFactory(width, height, path + "%s.jpg"%ip, timeout))
|
||||||
|
|
||||||
reactor.runReturn()
|
reactor.runReturn()
|
||||||
app.exec_()
|
app.exec_()
|
||||||
@@ -37,11 +37,13 @@ class RFBScreenShotFactory(rfb.ClientFactory):
|
|||||||
"""
|
"""
|
||||||
@summary: Factory for screenshot exemple
|
@summary: Factory for screenshot exemple
|
||||||
"""
|
"""
|
||||||
|
__INSTANCE__ = 0
|
||||||
def __init__(self, password, path):
|
def __init__(self, password, path):
|
||||||
"""
|
"""
|
||||||
@param password: password for VNC authentication
|
@param password: password for VNC authentication
|
||||||
@param path: path of output screenshot
|
@param path: path of output screenshot
|
||||||
"""
|
"""
|
||||||
|
RFBScreenShotFactory.__INSTANCE__ += 1
|
||||||
self._path = path
|
self._path = path
|
||||||
self._password = password
|
self._password = password
|
||||||
|
|
||||||
@@ -52,8 +54,10 @@ class RFBScreenShotFactory(rfb.ClientFactory):
|
|||||||
@param reason: str use to advertise reason of lost connection
|
@param reason: str use to advertise reason of lost connection
|
||||||
"""
|
"""
|
||||||
log.info("connection lost : %s"%reason)
|
log.info("connection lost : %s"%reason)
|
||||||
reactor.stop()
|
RFBScreenShotFactory.__INSTANCE__ -= 1
|
||||||
app.exit()
|
if(RFBScreenShotFactory.__INSTANCE__ == 0):
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
"""
|
"""
|
||||||
@@ -62,8 +66,10 @@ class RFBScreenShotFactory(rfb.ClientFactory):
|
|||||||
@param reason: str use to advertise reason of lost connection
|
@param reason: str use to advertise reason of lost connection
|
||||||
"""
|
"""
|
||||||
log.info("connection failed : %s"%reason)
|
log.info("connection failed : %s"%reason)
|
||||||
reactor.stop()
|
RFBScreenShotFactory.__INSTANCE__ -= 1
|
||||||
app.exit()
|
if(RFBScreenShotFactory.__INSTANCE__ == 0):
|
||||||
|
reactor.stop()
|
||||||
|
app.exit()
|
||||||
|
|
||||||
|
|
||||||
def buildObserver(self, controller, addr):
|
def buildObserver(self, controller, addr):
|
||||||
@@ -132,7 +138,7 @@ def help():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#default script argument
|
#default script argument
|
||||||
path = "/tmp/rdpy-vncscreenshot.jpg"
|
path = "/tmp/"
|
||||||
password = ""
|
password = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -148,20 +154,23 @@ if __name__ == '__main__':
|
|||||||
elif opt == "-p":
|
elif opt == "-p":
|
||||||
password = arg
|
password = arg
|
||||||
|
|
||||||
|
|
||||||
if ':' in args[0]:
|
|
||||||
ip, port = args[0].split(':')
|
|
||||||
else:
|
|
||||||
ip, port = args[0], "5900"
|
|
||||||
|
|
||||||
#create application
|
#create application
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
|
||||||
#add qt4 reactor
|
#add qt4 reactor
|
||||||
import qt4reactor
|
import qt4reactor
|
||||||
qt4reactor.install()
|
qt4reactor.install()
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
reactor.connectTCP(ip, int(port), RFBScreenShotFactory(password, path))
|
|
||||||
|
|
||||||
|
for arg in args:
|
||||||
|
if ':' in arg:
|
||||||
|
ip, port = arg.split(':')
|
||||||
|
else:
|
||||||
|
ip, port = arg, "5900"
|
||||||
|
|
||||||
|
reactor.connectTCP(ip, int(port), RFBScreenShotFactory(password, path + "%s.jpg"%ip))
|
||||||
|
|
||||||
|
|
||||||
reactor.runReturn()
|
reactor.runReturn()
|
||||||
app.exec_()
|
app.exec_()
|
||||||
@@ -463,8 +463,9 @@ class CompositeType(Type):
|
|||||||
if not self._readLen is None and readLen > self._readLen.value:
|
if not self._readLen is None and readLen > self._readLen.value:
|
||||||
#roll back
|
#roll back
|
||||||
s.pos -= sizeof(self.__dict__[name])
|
s.pos -= sizeof(self.__dict__[name])
|
||||||
#and notify
|
#and notify if not optional
|
||||||
raise InvalidSize("Impossible to read type %s : read length is too small"%(self.__class__))
|
if not self.__dict__[name]._optional:
|
||||||
|
raise InvalidSize("Impossible to read type %s : read length is too small"%(self.__class__))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Error during read %s::%s"%(self.__class__, name))
|
log.error("Error during read %s::%s"%(self.__class__, name))
|
||||||
|
|||||||
3
setup.py
3
setup.py
@@ -4,7 +4,7 @@ import setuptools
|
|||||||
from distutils.core import setup, Extension
|
from distutils.core import setup, Extension
|
||||||
|
|
||||||
setup(name='rdpy',
|
setup(name='rdpy',
|
||||||
version='1.1.0',
|
version='1.1.1',
|
||||||
description='Remote Desktop Protocol in Python',
|
description='Remote Desktop Protocol in Python',
|
||||||
long_description="""
|
long_description="""
|
||||||
RDPY is a pure Python implementation of the Microsoft RDP (Remote Desktop Protocol) protocol.
|
RDPY is a pure Python implementation of the Microsoft RDP (Remote Desktop Protocol) protocol.
|
||||||
@@ -34,6 +34,7 @@ setup(name='rdpy',
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
'twisted',
|
'twisted',
|
||||||
'pyopenssl',
|
'pyopenssl',
|
||||||
|
'service_identity'
|
||||||
'qt4reactor',
|
'qt4reactor',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user