Skip to content
Advertisement

P2P RDP with Python

I want to write a Simple P2P RDP Client and Server in Python. This is how I Sketched it out.

  1. Take Screenshots in short Interval
  2. Compress them and send to the server application
  3. Get Keyboard, Mouse events from server application. Serialize them and send to client. Client will unserialize them and will use SendInput Calls to reflect them

and What I need to know is

  1. Do there exist and rdp library in Python that I can use to simplify my Job ?
  2. How to get Keyboard or Mouse Event from Server Operator with Python ?
  3. Whats the easiest and simplest way of serialization of events ?
  4. How can I measure the relative X,Y coordinates of Mouseevent ?
  5. can you provide any example thats easy to follow ?
  6. and the Final question I’ve heard it will be easier to do it in .net if both the platforms are using Microsoft derivative OS. Is it true ?

My Client Application will run in Windows XP,Vista,7 and the server Application will run on Windows/Linux and also Please mention If I am missing something.

Advertisement

Answer

Some time ago I wrote something called easyrfb which, too, is based on python-vnc-viewer, but I never published it. It does not cover exactly what you asked, but it is very similar. In the hope it might be helpful, parts of it now can be found at http://hydra.geht.net/easyrfb/

Note that the files there are not always in a working state, because the files are directly linked to my working copy. But I am not editing often.

It’s now available on GitHub, too: https://github.com/hilbix/pyrfb/tree/easyrfb

This it what it does at my side:

  • Connect to a locally running Xvnc (technically any VNC server will do)
  • Continuously write the current screen contents to a highly compressed test.jpg
  • Some web page grabs that using AJAX and updates an image
  • Mouse clicks on that image are forwarded to the VNC server as mouse clicks
  • Keyboard input can be simulated using forms
  • And one can take lossless PNG screenshots
  • There is an edit.html to do fuzzy matching based on the PNG screenshots (called templates)
  • Shell scripts can check if such templates are matched or wait for them to match.

The internal communication is done using TCP, Unix-Sockets and some files, so it’s not difficult to change it such, that every component runs at a different location:

  • The VNC server (the screen to show)
  • rfbimg.py (which does VNC -> image and offers the control .sock)
  • The shell scripts (if needed, using sendsock.py to talk to .sock)
  • The web service (AJAX, and GET image) with stubs (forwarding commands to .sock)
  • The controlling web client (any browser, even lynx or telnet can do)

Please do not ask me for documentation! Use the source, Luke!

Mental health warning! The complete picture is a big and ugly grown unclean pile of headache-inducing-facepalm creating bits of mostly unrelated randomly placed complex scripts with wrong and misleading names, unclean copies, uncommented and unfinished half-edits, everything hardcoded to exactly one single machine, probably needing some undocumented local 10 year old tweaks to nonupgraded packages, or even older stuff. So I will not hand out everything. (And even if this sounds familiar, nope, I am not working for Microsoft.)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement