-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinterface.py
276 lines (224 loc) · 12.8 KB
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#Author: Dustin Grady
#Purpose: Draw GUI
#Status: In development
#To do:
# -Clean up self declarations outside of init
from tkinter.ttk import Progressbar
import tkinter as tk
import threading
import scanner
import fileio
import utils
class GUI(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) # Make sure to call this when overriding parent methods
self.title('Network Crawler v0.1')
GUI.build_gui(self)
self.configuration = fileio.read_config()
self.net_mon = scanner.NetworkMonitor(self)
self.MAX_THREADS = 256
GUI.update_status(self, 'Press "Start" to begin search')
def build_gui(self):
'''File menu'''
menubar = tk.Menu(self)
file_menu = tk.Menu(menubar, tearoff=0)
file_menu.add_command(label="Configure", command=self.config_window)
file_menu.add_command(label="About", command=self.about_window)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=GUI.quit)
menubar.add_cascade(label="File", menu=file_menu)
self.config(menu=menubar)
'''Logo'''
photo = tk.PhotoImage(file="./assets/logo.png")
logo_label = tk.Label(self, image=photo)
logo_label.grid(row=0, column=0, padx=50, pady=20)
logo_label.image = photo
'''Start/Stop buttons'''
button_frame = tk.Frame(self)
button_frame.grid(row=1, column=0, padx=50, pady=20)
start_button = tk.Button(button_frame, text="Start", command=lambda: (start_button.config(state='disabled'), stop_button.config(state='normal'), self.net_mon.start_scan()))
start_button.pack(side='left')
stop_button = tk.Button(button_frame, text="Stop", command=lambda: (stop_button.config(state='disabled'), start_button.config(state='normal'), self.net_mon.stop_scan()))
stop_button.pack(side='left')
'''Results'''
results_frame = tk.Frame(self)
results_frame.grid(row=0, column=1)
# Canvas
results_canvas = tk.Canvas(results_frame, bd=0, width=625)
results_canvas.pack(fill='both', side='left')
# Display area
self.results_view_area = tk.Frame(results_canvas)
self.results_view_area.pack(side='top', fill='both')
self.results_view_area.bind("<Configure>", lambda x: results_canvas.config(scrollregion=results_canvas.bbox("all"))) # Resize scroll region when widget size changes
'''Progress'''
progress_frame = tk.Frame(self)
progress_frame.grid(row=1, column=1)
# Current IP Address
ip_progress_frame = tk.Frame(progress_frame)
ip_progress_frame.grid(row=0, column=0)
progress_canvas = tk.Canvas(ip_progress_frame, bd=0, height=15)
progress_canvas.pack(side='left')
self.progress_view_frame = tk.Frame(progress_canvas)
self.progress_view_frame.pack(side='left')
# IP Progress Bar/ Percentage
progress_bar_frame = tk.Frame(progress_frame)
progress_bar_frame.grid(row=0, column=1)
self.scan_progress_bar = Progressbar(progress_bar_frame, orient='horizontal', length=275, mode='determinate')
self.scan_progress_bar.grid(row=0, column=1, padx=30, sticky='ew')
self.scan_percentage_frame = tk.Frame(progress_bar_frame)
self.scan_percentage_frame.grid(row=0, column=1)
'''Program description window'''
def about_window(self):
about_win = tk.Toplevel()
about_win.wm_title("About")
about_label = tk.Label(about_win,
text="Network Discovery Tool 2019\n A multithreaded network discovery tool designed to discover\n devices within a network and provide reports on the information gathered")
about_label.grid(row=0, column=0, padx=15, pady=15)
#about_win.geometry('325x70')
about_win.grab_set() # Modal
about_win.resizable(False, False)
'''Provides r/w access to config.ini'''
def config_window(self):
self.configuration = fileio.read_config()
config_win = tk.Toplevel()
config_frame = tk.Frame(config_win)
config_win.wm_title("Configuration")
config_label = tk.Label(config_frame, text="Configuration", font=('Helvetica', 10, 'bold')).pack(side='top')
config_frame.grid(row=0, column=0)
config_win.resizable(False, False)
'''IP Prefix Selection'''
ip_frame = tk.Frame(config_win)
ip_desc_label = tk.Label(ip_frame, text="Network prefix ").pack(side='left')
prefix1_val = tk.StringVar()
prefix2_val = tk.StringVar()
prefix1_val.set(self.configuration['IP_PREFIX'][0])
prefix2_val.set(self.configuration['IP_PREFIX'][1])
ip_prefix_form1 = tk.Entry(ip_frame, textvariable=prefix1_val, width=5).pack(side='left')
dot = tk.Label(ip_frame, text=" . ").pack(side='left')
ip_prefix_form2 = tk.Entry(ip_frame, textvariable=prefix2_val, width=5).pack(side='left')
ip_suffix = tk.Label(ip_frame, text=" . X . X").pack(side='left')
ip_frame.grid(row=1, column=0, pady=5, sticky='w')
'''Reports'''
report_frame = tk.Frame(config_win)
report_label = tk.Label(report_frame, text="Report frequency ").pack(side='left')
report_freq = ['Live', '1 hour', '6 hours', '12 hours', '24 hours', 'Never']
freq_choice = tk.StringVar(self)
freq_choice.set(self.configuration['REPORT'])
freq_menu = tk.OptionMenu(report_frame, freq_choice, *report_freq).pack(side='left')
report_frame.grid(row=2, column=0, pady=5, sticky='w')
'''Discovery Type'''
discovery_frame = tk.Frame(config_win)
report_label = tk.Label(discovery_frame, text="Discovery method ").pack(side='left')
disc_choice = tk.StringVar(self)
disc_choice.set(self.configuration['DISCOVERY'])
disc_menu = tk.OptionMenu(discovery_frame, disc_choice, *['ARP', 'Ping']).pack(side='left')
discovery_frame.grid(row=3, column=0, pady=5, sticky='w')
'''Thread Slider'''
thread_frame = tk.Frame(config_win)
thread_label = tk.Label(thread_frame, text="Threads").pack(side='left')
thread_slider = tk.Scale(thread_frame, from_=8, to=self.MAX_THREADS, resolution=8, length=150,
orient='horizontal')
thread_slider.set(self.configuration['THREADS'])
thread_slider.pack(side='left')
thread_frame.grid(row=5, column=0, pady=5, sticky='w')
'''Save Button'''
save_button = tk.Button(config_win, text="Save", command=lambda: (fileio.save_config(prefix1_val.get(), prefix2_val.get(), freq_choice.get(), disc_choice.get(), thread_slider.get()), config_win.destroy())) # Could probably be cleaned up (pass dict?)
save_button.grid(row=6, column=0, pady=5)
config_win.grab_set() # Modal
'''Updates results_window'''
def build_result(self):
self.tree = tk.ttk.Treeview(self.results_view_area, height=7, columns=('IP', 'MAC', 'Vendor'))
self.tree.heading('#0', text='IP')
self.tree.heading('#1', text='MAC')
self.tree.heading('#2', text='Vendor')
self.tree.heading('#3', text='Details')
self.tree.column('#0', minwidth=125, width=125, stretch=False)
self.tree.column('#1', minwidth=125, width=125, stretch=False)
self.tree.column('#2', minwidth=150, width=150, stretch=False)
self.tree.column('#3', minwidth=125, width=125, stretch=False)
self.tree.grid(row=0, column=1, sticky='nsew')
style = tk.ttk.Style(self.results_view_area)
style.configure('Treeview', rowheight=25)
for i, rec in enumerate(self.net_mon.record_list):
self.tree.insert('', 'end', tags=('evenrow' if i % 2 else 'oddrow', i), text=str(rec.ip), values=(str(rec.mac), str(rec.oui), "Click Me"))
self.tree.bind("<<TreeviewSelect>>", lambda i: GUI.details_window(self, self.net_mon.record_list[int(self.tree.item(self.tree.selection()[0], "tags")[1])])) # Referencing records using tag of their index
self.tree.tag_configure('evenrow', background='gray80')
self.tree.tag_configure('oddrow', background='gray60')
'''Clear our results'''
def clear_result_window(self):
for widget in self.results_view_area.winfo_children():
widget.destroy()
'''Update progress of scan'''
def update_status(self, status, scan_count=0):
ip_label = tk.Label(self.progress_view_frame, text=status)
if scan_count:
self.scan_progress_bar['value'] = ((65536-scan_count)/65536)*100 # Update progress/ loading bar here
#percentage_label = tk.Label(self.scan_percentage_frame, text=format((float((65536-scan_count)/65536)*100), '.3f') + ' %', font=('Helvetica', '7')) # Update percentage here
#percentage_label.grid(row=0, column=0)
ip_label.grid(row=0, column=0, sticky='ew')
'''Show more details of a device'''
def details_window(self, record):
details_win = tk.Toplevel()
details_win.title('Details')
self.details_frame = tk.Frame(details_win)
self.details_frame.pack(side='top')
self.progress_label = tk.Label(self.details_frame, text="Gathering information..")
self.progress_label.grid(row=0, column=0, columnspan=2)
self.details_progress_bar = Progressbar(self.details_frame, orient='horizontal', length=100, mode='determinate')
self.details_progress_bar.grid(row=1, column=0, padx=30, columnspan=2, sticky='ew')
self.ip_label = tk.Label(self.details_frame, text="IP Address:")
self.ip_result_label = tk.Label(self.details_frame, text="Loading..")
self.ip_label.grid(row=2, column=0, padx=10, sticky='w')
self.ip_result_label.grid(row=2, padx=10, column=1, sticky='w')
self.mac_label = tk.Label(self.details_frame, text="MAC Address:")
self.mac_result_label = tk.Label(self.details_frame, text="Loading..")
self.mac_label.grid(row=3, column=0, padx=10, sticky='w')
self.mac_result_label.grid(row=3, padx=10, column=1, sticky='w')
self.oui_label = tk.Label(self.details_frame, text="Vendor:")
self.oui_result_label = tk.Label(self.details_frame, text="Loading..")
self.oui_label.grid(row=4, column=0, padx=10, sticky='w')
self.oui_result_label.grid(row=4, padx=10, column=1, sticky='w')
self.os_label = tk.Label(self.details_frame, text="OS/ Accuracy:")
self.os_result_label = tk.Label(self.details_frame, text="Loading..")
self.os_label.grid(row=5, column=0, padx=10, sticky='w')
self.os_result_label.grid(row=5, padx=10, column=1, sticky='w')
self.port_label = tk.Label(self.details_frame, text="Port Status:")
self.port_placeholder_label = tk.Label(self.details_frame, text="Loading..")
self.port_label.grid(row=6, column=0, padx=10, sticky='w')
self.port_placeholder_label.grid(row=6, padx=10, column=1, sticky='w')
self.details_thread = threading.Thread(target=lambda: (GUI.build_details(self, record))) # Start thread to get results
self.details_thread.start()
#details_win.grab_set() # Modal (Causing error)
details_win.resizable(False, False)
def build_details(self, record):
self.ip_result_label.config(text=str(record.ip))
self.details_progress_bar['value'] = 10
self.mac_result_label.config(text=str(record.mac))
self.details_progress_bar['value'] = 20
self.oui_result_label.config(text=str(record.oui))
self.details_progress_bar['value'] = 30
record.op_sys, record.op_acc = utils.retrieve_os(record)
self.net_mon.record_list[(utils.get_record_index(record.ip, self.net_mon.record_list))].op_sys = record.op_sys # Update record object
self.net_mon.record_list[(utils.get_record_index(record.ip, self.net_mon.record_list))].op_acc = record.op_acc
self.os_result_label.config(text=record.op_sys + '/ ' + record.op_acc + '%')
self.details_progress_bar['value'] = 70
try:
for i, port in enumerate(utils.retrieve_port_status(record)):
self.net_mon.record_list[(utils.get_record_index(record.ip, self.net_mon.record_list))].ports.append(port)
self.port_placeholder_label.config(text="")
self.port_result_label = tk.Label(self.details_frame)
self.port_result_label.config(text=port)
self.port_result_label.grid(row=i+6, column=1, sticky='w')
except TypeError:
self.port_placeholder_label.config(text="None detected")
self.details_progress_bar['value'] = 100
self.progress_label.config(text="Scan complete")
'''
def error_window(self, msg):
tk.messagebox.showinfo("Error", msg)
'''
if __name__ == '__main__':
app = GUI()
app.geometry('925x275')
app.resizable(False, False)
app.mainloop()