SHARE
TWEET

Untitled

a guest May 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import sys, os, socket, subprocess, getpass
  4.  
  5. if len(sys.argv) < 5:
  6.     print "Usage: <IP/hostname> <command> <username> <password/->"
  7.     sys.exit(1)
  8.  
  9. # Make sure our directory exists
  10. rdesktop_dir=os.path.expanduser('~/.rdesktop/')
  11. if not os.path.exists(rdesktop_dir):
  12.     os.mkdir(rdesktop_dir)
  13.  
  14. # Check for existing socket
  15. socket_path=rdesktop_dir+'socket-'+sys.argv[1]+'-'+sys.argv[3]
  16. if os.path.exists(socket_path):
  17.     # We have a socket so try to use it
  18.     try:
  19.         s=socket.socket(socket.AF_UNIX)
  20.         s.connect(socket_path)
  21.         s.send(sys.argv[2])
  22.         s.close()
  23.         sys.exit(0)
  24.     except:
  25.         # We failed to start the command so re-establish the socket
  26.         pass
  27. else:
  28.     # We don't have a socket so start rdesktop from scratch
  29.  
  30.     # Check if we were supplied a password
  31.     if sys.argv[4] == '-':
  32.         sys.argv[4] = getpass.getpass()
  33.  
  34.     # Build a parameter list
  35.     cmd=['rdesktop',
  36.         '-a','16',
  37.         '-u',sys.argv[3],
  38.         '-p',sys.argv[4],
  39.         '-s','c:\seamlessrdp\seamlessrdpshell.exe '+sys.argv[2],
  40.         '-d','RLNX',
  41.         '-x','l',
  42.         '-r','sound:local',
  43.         '-r','clipboard:PRIMARYCLIPBOARD',
  44.         '-k','en-us',
  45.         '-A',
  46.         '-M',socket_path,
  47.         sys.argv[1]
  48.     ]
  49.     pid = os.fork()
  50.     if pid == 0:
  51.         process=subprocess.Popen(cmd)
  52.         process.wait()
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top