To achieve the functionality of only displaying the detection result once and returning to the main interface, you can modify the code as follows:

  1. Add a flag variable to indicate whether an attack has been detected:
def detect_attack():
    with open("clients.txt", "r") as f:
        clients = f.readlines()
        attack_detected = False  # flag variable
        for client in clients:
            ...
  1. If an attack is detected, set the flag to True and break out of the loop:
if sniff_count > 100:
    attack_detected = True
    messagebox.showwarning("警告", "检测到攻击源IP地址为" + ip + ",MAC地址为" + mac + "!")
    with open("detection_log.txt", "a") as f:
        f.write("警告"+ "检测到攻击源IP地址为" + ip + ",MAC地址为" + mac + "!\n")
    break  # break out of the loop
  1. After the loop, check the flag and display the appropriate message:
if attack_detected:
    messagebox.showwarning("警告", "检测到攻击源!")
else:
    messagebox.showinfo("提示", "未检测到攻击源!")
with open("detection_log.txt", "a") as f:
    f.write("检测结果:" + ("检测到攻击源!" if attack_detected else "未检测到攻击源!") + "\n")

With these modifications, the code will only display the detection result once and return to the main interface

def detect_attack with openclientstxt r as f clients = freadlines for client in clients ip = clientsplit0 mac = clientsplit1 sniff_filter = arp and sr

原文地址: https://www.cveoy.top/t/topic/frZD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录