|
| 1 | +""" |
| 2 | + Author : Daljeet Singh Chhabra |
| 3 | + Language : Python |
| 4 | + File Name : main.py |
| 5 | + Date Created : 28-12-2019 |
| 6 | + Last Modified : 28-12-2019 |
| 7 | +""" |
| 8 | + |
| 9 | +from tkinter import Entry, Label, StringVar, Tk, Listbox, Scrollbar, Button, END |
| 10 | +import paramiko |
| 11 | + |
| 12 | + |
| 13 | +def view_command(): |
| 14 | + server_response.delete(0, END) |
| 15 | + # Connect to remote host |
| 16 | + client = paramiko.SSHClient() |
| 17 | + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
| 18 | + client.connect(host_text.get(), username=uname_text.get(), password=password_text.get()) |
| 19 | + |
| 20 | + # SSHClient.exec_command() returns the tuple (stdin,stdout,stderr) |
| 21 | + try: |
| 22 | + stdout = client.exec_command(script_path_text.get())[1] |
| 23 | + for line in stdout: |
| 24 | + # Process each line in the remote output |
| 25 | + # print(line) |
| 26 | + server_response.insert(END, line) |
| 27 | + except: |
| 28 | + print('Execution failed') |
| 29 | + client.close() |
| 30 | + server_response.insert(END) |
| 31 | + |
| 32 | + |
| 33 | +window = Tk() |
| 34 | +window.title("Server Script Executer") |
| 35 | + |
| 36 | +host = Label(window, text="Host") |
| 37 | +host.grid(row=0, column=0) |
| 38 | + |
| 39 | +host_text = StringVar() |
| 40 | +host_entry = Entry(window, textvariable=host_text) |
| 41 | +host_entry.grid(row=0, column=1) |
| 42 | + |
| 43 | +script_path_label = Label(window, text="Script Path") |
| 44 | +script_path_label.grid(row=0, column=3) |
| 45 | + |
| 46 | +script_path_text = StringVar() |
| 47 | +script_path_entry = Entry(window, textvariable=script_path_text) |
| 48 | +script_path_entry.grid(row=0, column=4) |
| 49 | + |
| 50 | +uname_label = Label(window, text="Username") |
| 51 | +uname_label.grid(row=1, column=0) |
| 52 | + |
| 53 | +uname_text = StringVar() |
| 54 | +uname_entry = Entry(window, textvariable=uname_text) |
| 55 | +uname_entry.grid(row=1, column=1) |
| 56 | + |
| 57 | +password_label = Label(window, text="Password") |
| 58 | +password_label.grid(row=1, column=3) |
| 59 | + |
| 60 | +password_text = StringVar() |
| 61 | +password_entry = Entry(window, textvariable=password_text) |
| 62 | +password_entry.grid(row=1, column=4) |
| 63 | + |
| 64 | +server_response = Listbox(window, height=10, width=40) |
| 65 | +server_response.grid(row=3, column=0, rowspan=6, columnspan=3) |
| 66 | + |
| 67 | +s_bar = Scrollbar(window) |
| 68 | +s_bar.grid(row=2, column=3, rowspan=6) |
| 69 | + |
| 70 | +server_response.configure(yscrollcommand=s_bar.set) |
| 71 | +s_bar.configure(command=server_response.yview) |
| 72 | + |
| 73 | +# server_response.bind('<<ListboxSelect>>', get_selected_row) |
| 74 | + |
| 75 | +execute_button = Button(window, text="Execute", width=12, command=view_command) |
| 76 | +execute_button.grid(row=3, column=4) |
| 77 | + |
| 78 | +window.mainloop() |
0 commit comments