Sep-08-2017, 07:52 PM
I need a python(2.7) coder to help me with this script: (rdpy-rdpscreenshot.py)
Now i run this .bat:
THANK YOU!
P.S.
- here a succesull line:
i used a small tool to compare the 2 files and the diference is this:
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5 ------------------------------------------------------------------------------- -> from rdpy.core.error import RDPSecurityNegoFail 38 class RDPScreenShotFactory(rdp.ClientFactory): 39 """ 40 @summary: Factory for screenshot exemple 41 """ 42 __INSTANCE__ = 0 43 __STATE__ = [] 44 def __init__(self, reactor, app, width, height, path, timeout): 45 """ 46 @param reactor: twisted reactor 47 @param width: {integer} width of screen 48 @param height: {integer} height of screen (Pdb) 49 @param path: {str} path of output screenshot 50 @param timeout: {float} close connection after timeout s without any updating 51 """ 52 RDPScreenShotFactory.__INSTANCE__ += 1 53 self._reactor = reactor 54 self._app = app 55 self._width = width 56 self._height = height 57 self._path = path 58 self._timeout = timeout 59 #NLA server can't be screenshooting (Pdb) 60 self._security = rdp.SecurityLevel.RDP_LEVEL_SSL 61 62 def clientConnectionLost(self, connector, reason): 63 """ 64 @summary: Connection lost event 65 @param connector: twisted connector use for rdp connection (use reconnect to restart connection) 66 @param reason: str use to advertise reason of lost connection 67 """ 68 if reason.type == RDPSecurityNegoFail and self._security != "rdp": 69 log.info("due to RDPSecurityNegoFail try standard security layer") 70 self._security = rdp.SecurityLevel.RDP_LEVEL_RDP 71 connector.connect() 72 return 73 74 log.info("connection lost : %s"%reason) 75 RDPScreenShotFactory.__STATE__.append((connector.host, connector.port, reason)) 76 RDPScreenShotFactory.__INSTANCE__ -= 1 77 if(RDPScreenShotFactory.__INSTANCE__ == 0): 78 self._reactor.stop() 79 self._app.exit() 80 81 def clientConnectionFailed(self, connector, reason): (Pdb) 82 """ 83 @summary: Connection failed event 84 @param connector: twisted connector use for rdp connection (use reconnect to restart connection) 85 @param reason: str use to advertise reason of lost connection 86 """ 87 log.info("connection failed : %s"%reason) 88 RDPScreenShotFactory.__STATE__.append((connector.host, connector.port, reason)) 89 RDPScreenShotFactory.__INSTANCE__ -= 1 90 if(RDPScreenShotFactory.__INSTANCE__ == 0): 91 self._reactor.stop() 92 self._app.exit() (Pdb) 93 94 95 def buildObserver(self, controller, addr): 96 """ 97 @summary: build ScreenShot observer 98 @param controller: RDPClientController 99 @param addr: address of target 100 """ 101 class ScreenShotObserver(rdp.RDPClientObserver): 102 """ 103 @summary: observer that connect, cache every image received and save at deconnection (Pdb) 104 """ 105 def __init__(self, controller, width, height, path, timeout, reactor): 106 """ 107 @param controller: {RDPClientController} 108 @param width: {integer} width of screen 109 @param height: {integer} height of screen 110 @param path: {str} path of output screenshot 111 @param timeout: {float} close connection after timeout s without any updating 112 @param reactor: twisted reactor 113 """ 114 rdp.RDPClientObserver.__init__(self, controller) (Pdb) 115 self._buffer = QtGui.QImage(width, height, QtGui.QImage.Format_RGB32) 116 self._path = path 117 self._timeout = timeout 118 self._startTimeout = False 119 self._reactor = reactor 120 121 def onUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data): 122 """ 123 @summary: callback use when bitmap is received 124 """ 125 image = RDPBitmapToQtImage(width, height, bitsPerPixel, isCompress, data); (Pdb) 126 with QtGui.QPainter(self._buffer) as qp: 127 #draw image 128 qp.drawImage(destLeft, destTop, image, 0, 0, destRight - destLeft + 1, destBottom - destTop + 1) 129 if not self._startTimeout: 130 self._startTimeout = False 131 self._reactor.callLater(self._timeout, self.checkUpdate) 132 133 def onReady(self): 134 """ 135 @summary: callback use when RDP stack is connected (just before received bitmap) 136 """ (Pdb) 137 log.info("connected %s"%addr) 138 139 def onSessionReady(self): 140 """ 141 @summary: Windows session is ready 142 @see: rdp.RDPClientObserver.onSessionReady 143 """ 144 pass 145 146 def onClose(self): 147 """ (Pdb) 148 @summary: callback use when RDP stack is closed 149 """ 150 log.info("save screenshot into %s"%self._path) 151 self._buffer.save(self._path) 152 153 def checkUpdate(self): 154 self._controller.close(); 155 156 controller.setScreen(width, height); 157 controller.setSecurityLevel(self._security) 158 return ScreenShotObserver(controller, self._width, self._height, self._path, self._timeout, self._reactor (Pdb) 159 160 def main(width, height, path, timeout, hosts): 161 """ 162 @summary: main algorithm 163 @param height: {integer} height of screenshot 164 @param width: {integer} width of screenshot 165 @param timeout: {float} in sec 166 @param hosts: {list(str(ip[:port]))} 167 @return: {list(tuple(ip, port, Failure instance)} list of connection state 168 """ 169 #create application (Pdb) 170 app = QtGui.QApplication(sys.argv) 171 172 #add qt4 reactor 173 import qt4reactor 174 qt4reactor.install() 175 176 from twisted.internet import reactor 177 178 for host in hosts: 179 if ':' in host: 180 ip, port = host.split(':') (Pdb) 181 else: 182 ip, port = host, "3389" 183 184 reactor.connectTCP(ip, int(port), RDPScreenShotFactory(reactor, app, width, height, path + "%s.jpg"%ip, t meout)) 185 186 reactor.runReturn() 187 app.exec_() 188 return RDPScreenShotFactory.__STATE__ 189 190 def help(): 191 print "Usage: rdpy-rdpscreenshot [options] ip[:port]" (Pdb) 192 print "\t-w: width of screen default value is 1024" 193 print "\t-l: height of screen default value is 800" 194 print "\t-o: file path of screenshot default(/tmp/rdpy-rdpscreenshot.jpg)" 195 print "\t-t: timeout of connection without any updating order (default is 2s)" 196 197 if __name__ == '__main__': 198 #default script argument 199 width = 1024 200 height = 800 201 path = "/tmp/" 202 timeout = 5.0 (Pdb) 203 204 try: 205 opts, args = getopt.getopt(sys.argv[1:], "hw:l:o:t:") 206 except getopt.GetoptError: 207 help() 208 for opt, arg in opts: 209 if opt == "-h": 210 help() 211 sys.exit() 212 elif opt == "-w": 213 width = int(arg) (Pdb) 214 elif opt == "-l": 215 height = int(arg) 216 elif opt == "-o": 217 path = arg 218 elif opt == "-t": 219 timeout = float(arg) 220 221 main(width, height, path, timeout, args)Original site: https://github.com/citronneur/rdpy
Now i run this .bat:
rdpy-rdpscreenshot.py -w 1024 -l 800 -o C:/tmp/ 23.228.142.165 rdpy-rdpscreenshot.py -w 1024 -l 800 -o C:/tmp/ 24.73.64.98 rdpy-rdpscreenshot.py -w 1024 -l 800 -o C:/tmp/ 23.228.144.93,everything goes well but the problem is that it stops at line 2 trying and re-trying to connect endlessly without going to the 3rd line (maybe NLA is activated),anyway all i want is to close & exit and pass to the 3rd line.
THANK YOU!
P.S.
- here a succesull line:
Error:C:\Python27\Scripts>rdpy-rdpscreenshot.py -w 1024 -l 800 -o C:/tmp/ 23.228.142.1
65
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 103, in callW
ithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 86, in callWi
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 122, in c
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 85, in ca
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\qtreactor\qt4base.py", line 100, in _read
data = w.doRead()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 208, in doR
ead
return self._dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 214, in _da
taReceived
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\nla\cssp.py", line 208,
in dataReceived
self._layer.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\core\layer.py", line 209, in dataRece
ived
self.recv(expectedData)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\tpkt.py", line 195, in r
eadData
self._presentation.recv(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\x224.py", line 199, in r
ecvConnectionConfirm
raise RDPSecurityNegoFail("negotiation failure code %x"%message.protocolNeg.
failureCode.value)
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 3
[*] INFO: save screenshot into C:/tmp/23.228.142.165.jpg
[*] INFO: due to RDPSecurityNegoFail try standard security layer
[*] WARNING: *******************************************
[*] WARNING: * RDP Security selected *
[*] WARNING: *******************************************
[*] INFO: connected IPv4Address(TCP, '23.228.142.165', 3389)
[*] INFO: save screenshot into C:/tmp/23.228.142.165.jpg
[*] INFO: connection lost : [Failure instance: Traceback (failure with no
frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed
- here problem line: Error:C:\Python27\Scripts>rdpy-rdpscreenshot.py -w 1024 -l 800 -o C:/tmp/ 24.73.34.125
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 103, in callW
ithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 86, in callWi
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 122, in c
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 85, in ca
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\qtreactor\qt4base.py", line 100, in _read
data = w.doRead()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 208, in doR
ead
return self._dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 214, in _da
taReceived
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\nla\cssp.py", line 208,
in dataReceived
self._layer.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\core\layer.py", line 209, in dataRece
ived
self.recv(expectedData)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\tpkt.py", line 195, in r
eadData
self._presentation.recv(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\x224.py", line 199, in r
ecvConnectionConfirm
raise RDPSecurityNegoFail("negotiation failure code %x"%message.protocolNeg.
failureCode.value)
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5
[*] INFO: save screenshot into C:/tmp/24.73.34.125.jpg
[*] INFO: due to RDPSecurityNegoFail try standard security layer
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 103, in callW
ithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 86, in callWi
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 122, in c
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 85, in ca
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\qtreactor\qt4base.py", line 100, in _read
data = w.doRead()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 208, in doR
ead
return self._dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 214, in _da
taReceived
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\nla\cssp.py", line 208,
in dataReceived
self._layer.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\core\layer.py", line 209, in dataRece
ived
self.recv(expectedData)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\tpkt.py", line 195, in r
eadData
self._presentation.recv(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\x224.py", line 199, in r
ecvConnectionConfirm
raise RDPSecurityNegoFail("negotiation failure code %x"%message.protocolNeg.
failureCode.value)
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5
[*] INFO: save screenshot into C:/tmp/24.73.34.125.jpg
[*] INFO: due to RDPSecurityNegoFail try standard security layer
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 103, in callW
ithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 86, in callWi
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 122, in c
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 85, in ca
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\qtreactor\qt4base.py", line 100, in _read
data = w.doRead()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 208, in doR
ead
return self._dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 214, in _da
taReceived
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\nla\cssp.py", line 208,
in dataReceived
self._layer.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\core\layer.py", line 209, in dataRece
ived
self.recv(expectedData)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\tpkt.py", line 195, in r
eadData
self._presentation.recv(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\x224.py", line 199, in r
ecvConnectionConfirm
raise RDPSecurityNegoFail("negotiation failure code %x"%message.protocolNeg.
failureCode.value)
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5
[*] INFO: save screenshot into C:/tmp/24.73.34.125.jpg
[*] INFO: due to RDPSecurityNegoFail try standard security layer
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 103, in callW
ithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 86, in callWi
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 122, in c
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 85, in ca
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\qtreactor\qt4base.py", line 100, in _read
data = w.doRead()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 208, in doR
ead
return self._dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 214, in _da
taReceived
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\nla\cssp.py", line 208,
in dataReceived
self._layer.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\core\layer.py", line 209, in dataRece
ived
self.recv(expectedData)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\tpkt.py", line 195, in r
eadData
self._presentation.recv(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\x224.py", line 199, in r
ecvConnectionConfirm
raise RDPSecurityNegoFail("negotiation failure code %x"%message.protocolNeg.
failureCode.value)
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5
[*] INFO: save screenshot into C:/tmp/24.73.34.125.jpg
[*] INFO: due to RDPSecurityNegoFail try standard security layer
Unhandled Error
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 103, in callW
ithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\log.py", line 86, in callWi
thContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 122, in c
allWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python27\lib\site-packages\twisted\python\context.py", line 85, in ca
llWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "C:\Python27\lib\site-packages\qtreactor\qt4base.py", line 100, in _read
data = w.doRead()
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 208, in doR
ead
return self._dataReceived(data)
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 214, in _da
taReceived
rval = self.protocol.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\nla\cssp.py", line 208,
in dataReceived
self._layer.dataReceived(data)
File "C:\Python27\lib\site-packages\rdpy\core\layer.py", line 209, in dataRece
ived
self.recv(expectedData)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\tpkt.py", line 195, in r
eadData
self._presentation.recv(data)
File "C:\Python27\lib\site-packages\rdpy\protocol\rdp\x224.py", line 199, in r
ecvConnectionConfirm
raise RDPSecurityNegoFail("negotiation failure code %x"%message.protocolNeg.
failureCode.value)
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5
[*] INFO: save screenshot into C:/tmp/24.73.34.125.jpg
[*] INFO: due to RDPSecurityNegoFail try standard security layer
rdpy.core.error.RDPSecurityNegoFail: negotiation failure code 5 [*] INFO: save screenshot into C:/tmp/24.73.34.125.jpg