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()
我有这个用鱼钩制成的arp欺骗工具,但是我试图通过使用tkinter很好地显示结果。问题是当我按下按钮扫描可能的攻击时,窗口冻结。我猜这是因为sniff()函数是一个长期运行的函数。有人可以帮助我以正确的方式进行这项工作吗?
答案 0 :(得分:0)
也许您可以尝试使用线程模块来防止其中断tkinter循环? 语法是这样的
import threading
sniffThread = threading.thread(target=sniff)
sniffThread.run()
sniffThread.stop()