1

我想以任何方式知道我可以将函数作为后台进程运行。我已经阅读了线程,但我仍然不清楚如何实现它。在我的系统中,当我单击按钮时,scapy 检测脚本会运行。但是当 scapy 函数正在运行时,系统将挂起。

我想要实现的是,当我单击启动 scapy 检测脚本的按钮时,我希望能够在同一系统中执行其他功能。(总体思路是防止系统挂起)

def startMonitor(self,event):       
        selectedInterface = self.interfaces_cblist.GetValue()
        #selectInterfaceStr = str(selectedInterface)    
        if len(selectedInterface) == 0:
            noInterfaceSelected = wx.MessageDialog(None,"Please select an interface","",wx.ICON_ERROR)
            noInterfaceSelected.ShowModal()
        else:
            #confirmMonitor = wx.MessageDialog(None,"Monitoring Start on %s interface"%selectedInterface,"",wx.OK)
            #confirmMonitor.ShowModal()
            x = selectedInterface
            thread.start_new_thread(self.camtableDetection(x))

    def camtableDetection(self,a):                  
        global interface        
        interface = str(a)
        THRESH=(254/4)
        START = 5

        def monitorPackets(p):
            if p.haslayer(IP):
                hwSrc = p.getlayer(Ether).src
                if hwSrc not in hwList:
                    hwList.append(hwSrc)
                delta = datetime.datetime.now() - start
                if((delta.seconds > START) and ((len(hwList)/delta.seconds) > THRESH)):
                    camAttackDetected = wx.MessageDialog(None,"Cam Attack Detected","",wx.ICON_ERROR)
                    camAttackDetected.ShowModal()

        hwList = []
        start = datetime.datetime.now()
        sniff(iface=interface,prn=monitorPackets)
4

0 回答 0