Guest User

Untitled

a guest
Jan 3rd, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. `linux memory and insert into textbox below` `i must put 3 methods, for each command>`
  2.  
  3. ***code is:***
  4.  
  5. class LoginFrame(Frame):
  6.  
  7. def __init__(self, master):
  8. super().__init__(master)
  9. self.label_ipa = Label(self, text="IP Address",font=("Times New Roman",14), fg="blue")
  10. self.label_username = Label(self, text="Username",font=("Times New Roman", 14), height=4, fg="blue")
  11. self.label_password = Label(self, text="Password",font=("Times New Roman", 14), height=4, fg="blue")
  12. self.entry_ipa = Entry(self,justify=CENTER)#.grid(row-0,column=1)
  13. self.entry_username = Entry(self,justify=CENTER)#.grid(row=0,column=1,pady=4)
  14. self.entry_password = Entry(self, show="*",justify=CENTER)
  15. self.label_ipa.grid(row=0,sticky=E)
  16. self.label_username.grid(row=1, sticky=E)
  17. self.label_password.grid(row=2, sticky=E)
  18. self.entry_ipa.grid(row=0,column=1)
  19. self.entry_username.grid(row=1, column=1)
  20. self.entry_password.grid(row=2, column=1)
  21. self.disct = Button(self, text="Close Session",command=self._disc_,font=("Times New Roman", 14), width=10,height=2, fg="red")
  22. self.logbtn = Button(self, text="Connecting", command=self._login_,font=("Times New Roman", 14), width=10,height=2, fg="green")
  23. self.logbtn.grid(row=3,column=0)
  24. self.disct.grid(row=3,column=2)
  25. self.pack()
  26.  
  27. def _login_(self):
  28.  
  29. ipa = self.entry_ipa.get()
  30.  
  31. username = self.entry_username.get()
  32. password = self.entry_password.get()
  33.  
  34. if not ipa:
  35. tk.messagebox.showerror("Error MessageBox","please Enter the IP Address",icon="warning")
  36. return False
  37.  
  38. if not username:
  39. tk.messagebox.showerror("Error MessageBox","please Enter Your Username",icon="warning")
  40. return False
  41. if not password:
  42. tk.messagebox.showerror("Error MessageBox","please Enter Your Password",icon="warning")
  43. return False
  44.  
  45. cl1=paramiko.SSHClient()
  46. cl1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  47. cl1.connect(ipa,username=username,password=password)
  48.  
  49. if(ipa==ipa and username==username and password==password):
  50.  
  51. tk.messagebox.showinfo("OPEN THE Session","SSH connection to %s established" %ipa)
  52.  
  53. else:
  54. #client_key
  55. tk.messagebox.showerror("Error MessageBox","please try again",icon="warning")
  56. window = Toplevel(root)
  57. window.title("Command Action")
  58. window.geometry("400x350+400+350")
  59. b1=Button(window,text="check Memory",bg="red",command=self._login_).place(x=0,y=0)
  60. b2=Button(window,text="Free disk Space",bg="red").place(x=100,y=0)
  61. b3=Button(window,text="Imprt XML FILE",bg="red").place(x=220,y=0)
  62. text=Text(window,height=10,width=50).place(x=0,y=50)
  63. stdin, stdout, stderr=cl1.exec_command("free -g")
  64. #print(stdout.read())
  65. text.insert(stdout.read())
  66. def _disc_(self):
  67.  
  68. MsgBox = tk.messagebox.askquestion ('Exit Application','Are you sure you want Dissconnecting ',icon = 'warning')
  69.  
  70. if MsgBox == "yes":
  71.  
  72. root.destroy()
  73.  
  74. else:
  75.  
  76. tk.messagebox.showinfo('Return','You will now return to the
  77. application screen')
  78.  
  79. root = tk.Tk()
  80. root.geometry('400x400+50+50')
  81. root.title('Connecting to Server')
  82. lf = LoginFrame(root)
  83. root.mainloop()
Add Comment
Please, Sign In to add comment