Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- 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
- 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
- of the PC of the receiver.
- '''
- from paramiko import SSHClient, AutoAddPolicy
- import pyperclip
- ssh = SSHClient()
- ssh.set_missing_host_key_policy(AutoAddPolicy())
- ssh.connect('IP_Adress', username='username', password='password', key_filename='path_to_key')
- outdata, errdata = '', ''
- ssh_transp = ssh.get_transport()
- chan = ssh_transp.open_session()
- chan.setblocking(1)
- chan.get_pty()
- chan.exec_command('wall -n')
- def copy_to_clip(string_to_copy):
- list_of_strings = string_to_copy.split('\n')
- list_of_strings = list_of_strings[3:]
- string_to_copy = '\n'.join(list_of_strings)
- pyperclip.copy(string_to_copy)
- # if you want to receive constantly then comment the below line
- quit()
- while True: # monitoring process
- # Reading from output streams
- while chan.recv_ready():
- outdata += chan.recv(1000)
- print(copy_to_clip(outdata.decode('ascii')))
- # print stdout.readlines()
- while chan.recv_stderr_ready():
- errdata += chan.recv_stderr(1000)
- print(errdata)
- if chan.exit_status_ready(): # If completed
- break
- ssh_transp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement