Guest User

Untitled

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