import tkinter as tk
import random
import scapy.all as scapy
result = ""
def getmac(ip):
arplayer = scapy.ARP(pdst=ip)
etherlayer = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
packet = etherlayer/arplayer
answeredList = scapy.srp(packet, timeout=2, verbose = False)[0]
return answeredList[0][1].hwsrc
def sniff():
scapy.sniff(store=False, prn=checkattack)
def checkattack(packet):
try:
if packet.haslayer(scapy.ARP) and packet[scapy.ARP].op == 2:
realmac = getmac(packet[scapy.ARP].psrc)
rspmac = packet[scapy.ARP].hwsrc
if realmac != rspmac:
result = "WARNING"
except IndexError:
pass
GUI = tk.Tk()
GUI.title("NETWORK GUARDIAN")
GUI.geometry("600x500")
# === labels ===
label1 = tk.Label(text="> Welcome to the NETWORK GUARDIAN !", font=("Times", 11))
label1.grid(column = 0, row = 0)
label2 = tk.Label(text = result, font=("Arial Black", 15))
label2.grid(column = 0, row = 3)
# === buttons ===
button1 = tk.Button(text="Scan for attacks", command = sniff)
button1.grid(column = 0, row = 2)
GUI.mainloop()
I have this arp spoofing tool made with scapy, but I am trying to display the results in a nicely way by using tkinter. The problem is that when I press the button to scan for possible attacks the window freezes. I guess this happens because the sniff() function is a long-running function. Can someone help me to make this work the right way?
Maybe you could try the threading module to keep it from interrupting the tkinter loop? The syntax is something like this
import threading
sniffThread = threading.thread(target=sniff)
sniffThread.run()
sniffThread.stop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.