Advertisement
Guest User

Untitled

a guest
May 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. '''
  2. Use this python file to copy the command of wall output to clipboard. The sender needs to login into remote system and send the output he intends the receiver to receive
  3. in the wall command. The receiver needs to run this script, please input the credentials of the same server in which the sender has logged in, whenever the script receives the output it gets copied into clipboard
  4. of the PC of the receiver.
  5. '''
  6. from paramiko import SSHClient, AutoAddPolicy
  7. import pyperclip
  8. ssh = SSHClient()
  9. ssh.set_missing_host_key_policy(AutoAddPolicy())
  10. ssh.connect('IP_Adress', username='username', password='password', key_filename='path_to_key')
  11. outdata, errdata = '', ''
  12. ssh_transp = ssh.get_transport()
  13. chan = ssh_transp.open_session()
  14. chan.setblocking(1)
  15. chan.get_pty()
  16. chan.exec_command('wall -n')
  17. def copy_to_clip(string_to_copy):
  18. list_of_strings = string_to_copy.split('\n')
  19. list_of_strings = list_of_strings[3:]
  20. string_to_copy = '\n'.join(list_of_strings)
  21. pyperclip.copy(string_to_copy)
  22. # if you want to receive constantly then comment the below line
  23. quit()
  24. while True: # monitoring process
  25. # Reading from output streams
  26. while chan.recv_ready():
  27. outdata += chan.recv(1000)
  28. print(copy_to_clip(outdata.decode('ascii')))
  29. # print stdout.readlines()
  30. while chan.recv_stderr_ready():
  31. errdata += chan.recv_stderr(1000)
  32. print(errdata)
  33. if chan.exit_status_ready(): # If completed
  34. break
  35. ssh_transp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement