Advertisement
tsounakis

net manager 0.2 DIRECTOR'S CUT

Jan 14th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.94 KB | None | 0 0
  1. import socket as sc
  2. import tkinter as tk
  3. import tkinter.scrolledtext as scr
  4. #import pyperclip
  5. import subprocess
  6. import datetime
  7. from os.path import dirname, join
  8. from time import gmtime, strftime
  9.  
  10. global hostname, IP_address
  11.  
  12. current_dir = dirname(__file__)
  13. image_path = join(current_dir, "net.png")
  14.  
  15. class main_win():
  16.     def __init__(self, master):
  17.         self.master = master
  18.         self.master.option_add("*Font", 'arial 10')
  19.         self.master.title('Net Manager 0.2 Alpha')
  20.         self.master = master
  21.         self.master.configure(background = 'white')
  22.         self.master.resizable(False, False)
  23.         self.masterback = tk.Frame(height = 300, width = 500)
  24.         self.masterback.pack()
  25.         self.masterback.configure(background = 'white')
  26.          
  27.         self.Message = tk.Label(master, text='Welcome to Net Manager 0.2 Alpha Build - Exclusive Alpha Access.')
  28.         self.Message.place(relx= 0.5, rely = 0.105, anchor = 'center')
  29.         self.Message.configure(background = 'white')
  30.  
  31.         self.show_ip = tk.Button(master, text = 'Show host IP address', command = self.print_ip)
  32.         self.show_ip.place(relx= 0.62, rely = 0.575)
  33.         self.show_ip.configure(background = 'white')
  34.                        
  35.         self.ip_entry = tk.Entry(master)
  36.         self.ip_entry.place(relx = 0.1, rely = 0.6)
  37.         self.ip_entry.configure(background = 'white')
  38.        
  39.         self.show_hostname = tk.Button(master, text = 'Show hostname', command = self.print_hn)
  40.         self.show_hostname.place(relx= 0.62, rely = 0.475)
  41.         self.show_hostname.configure(background = 'white')
  42.        
  43.         self.show_wifi_password = tk.Button(master, text = 'Show Wifi password', command = self.find_wifi_password)
  44.         self.show_wifi_password.place(relx= 0.62, rely = 0.375)
  45.         self.show_wifi_password.configure(background = 'white')
  46.                        
  47.         self.hostname_entry = tk.Entry(master)
  48.         self.hostname_entry.place(relx = 0.1, rely = 0.5)
  49.         self.hostname_entry.configure(background = 'white')
  50.        
  51.         img = tk.PhotoImage(file = image_path)
  52.         self.master.label= tk.Label(self.master, image = img)
  53.         self.master.label.image = img
  54.         self.master.label.place(relx = 0.08, rely= 0.175, anchor="s")
  55.         self.master.label.configure(background = 'white')
  56.  
  57.         self.log_label = tk.Label(self.master, bg = 'white', text = 'Action log:')
  58.         self.log_label.place(rely = 0.69, relx = 0.02)
  59.         self.log_frame = tk.Frame(master, bg = 'white')
  60.         self.log_frame.pack(fill = 'both', expand = 'yes')
  61.         self.log = scr.ScrolledText(
  62.             master = self.log_frame,
  63.             wrap = 'word',
  64.             width = 75,
  65.             height = 5
  66.         )
  67.         self.log.pack(padx = 10, pady = 10, fill = 'both', expand = 'True')
  68.         self.log.insert('insert', 'Your network: ' + self.find_nw_name() + '\n')
  69.  
  70.     def print_hn(self):
  71.         self.hostname_entry.delete(0, 'end')
  72.         self.hostname_entry.insert(0, hostname)
  73.        
  74.     def print_ip(self):
  75.         self.ip_entry.delete(0, 'end')
  76.         self.ip_entry.insert(0, IP_address)
  77.        
  78.         self.copy_ip()
  79.         self.print_to_log()
  80.  
  81.     def find_nw_name(self):
  82.         self.nw_str = (str(subprocess.check_output('netsh wlan show interfaces')))
  83.         self.nw_lst = self.nw_str.split()
  84.         idx = self.nw_lst.index('SSID')
  85.         idx += 2
  86.         return self.nw_lst[idx][:-4]
  87.    
  88.     def copy_ip(self):
  89.         #pyperclip.copy(self.ip_entry.get())
  90.         #spam = pyperclip.paste()
  91.         pass
  92.  
  93.  
  94.     def print_to_log(self):
  95.         self.log.insert('insert', str(strftime('%Y.%m.%d, %H:%M:%S', gmtime())) + ' // Shown ' + hostname +'\'s IP address and copied it to clipboard.' + '\n')
  96.  
  97.     def find_wifi_password(self):
  98.         data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors="backslashreplace").split('\n')
  99.         profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i]
  100.         self.log.insert('insert', '\nYour PC has these saved - recently used networks and their passwords:\n\nNAME OF NETWORK       PASSWORD\n')
  101.         for i in profiles:
  102.             try:
  103.                 results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8', errors="backslashreplace").split('\n')
  104.                 results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
  105.                 try:
  106.                     self.log.insert('insert', str(i) + ' : ' + str(results[0]) + '\n')
  107.                 except IndexError:
  108.                     self.log.insert('insert', str(i) + ": OpenNetwork\n")
  109.             except subprocess.CalledProcessError:
  110.                 self.log.insert('insert', (i, "ENCODING ERROR"))
  111.         self.log.insert('insert', '\n')
  112.        
  113.  
  114. hostname = sc.gethostname()
  115. IP_address = sc.gethostbyname(hostname)
  116.  
  117. root = tk.Tk()
  118.  
  119. window = main_win(root)
  120. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement