-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUI.py
125 lines (97 loc) · 3.75 KB
/
GUI.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
#using Scapy in a python script requires the .py file to be ran in root privilage
#run this .py file using: sudo python3 filename
import tkinter as tk
import sys
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
import threading
import collections
import scapy.all as scapy
from collections import Counter
thread = None
should_stop = False
subdomain = ''
source_ip_dict = collections.defaultdict(list)
count = Counter()
def start_sniffing():
print("start sniffing")
global should_stop
global thread
global subdomain
subdomain = subdomain_entry.get()
if (thread is None) or (not thread.is_alive()):
should_stop = False
thread = threading.Thread(target=sniffing).start()
def handler(packet):
global source_ip_dict
global subdomain
global count
treev
#print(packet.show())
print(packet.summary())
if 'IP' in packet:
src_ip = packet['IP'].src
dest_ip = packet['IP'].dst
for ip in source_ip_dict:
count[ip] += 1
if src_ip[0:len(subdomain)] == subdomain:
if src_ip not in source_ip_dict:
source_ip_dict[src_ip].append(dest_ip)
row = treev.insert('', tk.END, text=src_ip, values = (src_ip, count.get(dest_ip)))
treev.insert(row, tk.END, text=dest_ip, values=(dest_ip))
treev.pack(fill=tk.X)
else:
if dest_ip not in source_ip_dict[src_ip]:
source_ip_dict[src_ip].append(dest_ip)
cur_item = treev.focus()
if (treev.item(cur_item)['text'] == src_ip):
treev.insert(cur_item, tk.END, text=dest_ip,values= (dest_ip))
#this is where we find the specific row in the table and update the frequency
# Find the item with the name 'Jane'
item = None
for child in treev.get_children():
if treev.item(child)['values'][0] == 'Jane':
item = child
break
if item is not None:
treev.selection_set(item)
treev.item(treev.selection(), values=(src_ip, count.get(dest_ip)))
def sniffing():
scapy.sniff(prn=handler, stop_filter=stop_sniffing)
print(count)
def stop_sniffing(packet):
global should_stop
return should_stop
def stop_button():
global should_stop
should_stop = True
root = tk.Tk()
root.configure(bg = "yellow")
root.title("Packet Sniffer")
root.minsize(800, 800)
label = tk.Label(
root, text="Welcome to the python networking tool", font=('Arial', 18))
label.pack(padx=20, pady=20)
buttonframe = tk.Frame(root, bg = "red")
buttonframe.columnconfigure(0, weight=1)
buttonframe.columnconfigure(1, weight=1)
# buttonframe.columnconfigure(2,weight=1)
btn1 = tk.Button(buttonframe, text="Start Sniffing",
font=('Arial', 18),fg='green',
activebackground='red', command=start_sniffing)
btn2 = tk.Button(buttonframe, text="End Sniffing",
font=('Arial', 18), fg='green',
activebackground='red', command=stop_button)
btn1.grid(row=0, column=0, sticky=tk.W+tk.E)
btn2.grid(row=0, column=1, sticky=tk.W+tk.E)
buttonframe.pack(fill='x')
subdomain_entry = tk.Entry(root)
subdomain_entry.pack(ipady=5, ipadx=50, pady=10)
treev = ttk.Treeview(root, height=400, column = ("IP","Frequency"),show = 'headings')
treev.column('#0', minwidth=10, width=12)
treev.column("#1")
treev.column("#2")
treev.heading("#0",text = "Type")
treev.heading("#1", text = "address")
treev.heading("#2",text = "frequency")
root.mainloop()