class MainWindow: def init(self): self.root = tk.Tk() self.root.title('ARP Detector') self.root.geometry('400x350') self.timeout = 60 # default timeout value self.timer = 0 self.stop_event = threading.Event()

    self.arp_button = tk.Button(self.root, text='ARP Detection', command=self.show_arp_page)
    self.arp_button.pack()

    self.icmp_button = tk.Button(self.root, text='ICMP Flood Detection', command=self.start_detection)
    self.icmp_button.pack()

    self.tcp_button = tk.Button(self.root, text='TCP Attack Detection', command=self.start_tcp_detection)
    self.tcp_button.pack()

    self.network_button = tk.Button(self.root, text='Network Scanner', command=self.start_detection)
    self.network_button.pack()

    self.root.mainloop()

def show_arp_page(self):
    self.arp_page = tk.Toplevel(self.root)
    ArpDetectorPage(self.arp_page)

    self.network_button = tk.Button(self.root, text='Network Scanner', command=self.toggle_network_scanner, state=tk.DISABLED)
    self.network_button.pack()

    self.timeout_label = tk.Label(self.root, text='Detection Time (s)')
    self.timeout_label.pack()
    self.timeout_entry = tk.Entry(self.root)
    self.timeout_entry.pack()

    self.set_timeout_button = tk.Button(self.root, text='Set Timeout', command=self.set_timeout)
    self.set_timeout_button.pack()

    self.root.mainloop()

def set_timeout(self):
    try:
        self.timeout = int(self.timeout_entry.get())
        self.timer = 0
        self.stop_event.clear()
        print(f'Timeout set to {self.timeout} seconds')
    except ValueError:
        print('Invalid timeout value')

def start_tcp_detection(self):
    self.timer = 0
    self.stop_event.clear()
    self.tcp_thread = threading.Thread(target=self.detect_tcp_attack)
    self.tcp_thread.start()

def detect_tcp_attack(self):
    # code for detecting TCP attack
    pass

def stop_tcp_detection(self):
    self.stop_event.set()
    self.tcp_thread.join()

def run(self):
    while not self.stop_event.is_set():
        self.detect_tcp_attack()
        time.sleep(5)
        self.timer += 5
        if self.timer >= self.timeout:
            print('No TCP attack detected')
            self.stop_event.set()
Python GUI ARP Detector with Timeout Feature

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

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