python运行scapy函数作为后台进程

时间:2013-09-30 07:23:42

标签: python

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

我想要实现的是当我点击启动scapy检测脚本的按钮时,我希望能够在同一系统中执行其他功能。(一般的想法是防止系统挂起)< / p>

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)

0 个答案:

没有答案