wxpython appendtext to textcontrol in real time

Dear all,

I am developing an intrusion detection system in real time.Thus , i would like those result to be appended to my textcontrol.However , i am unable to append it.It is because the function run in live(continuous) and append the textcontrol in live.How can i solve this problem which any output in real time be appended to my text control.I have try the standard way but its does not appear in my text control.

here is my code.

def startMonitor(self,event):
selectedInterface = self.interfaces_cblist.GetValue()
self.selectInterfaceStr = str(selectedInterface)
if len(selectedInterface) == 0:
noSelect_error = wx.MessageDialog(None,“Please select an interface”,"",wx.OK|wx.ICON_ERROR)
noSelect_error.ShowModal()
else:
monitorStarted = wx.MessageDialog(None,“Monitor on %s started”%self.selectInterfaceStr,"",wx.OK|wx.ICON_ERROR)
monitorStarted.ShowModal()
self.monitorInterface_button.Disable()
self.abortValue = 1;
self.camDetect = multiprocessing.Process(target=self.camtableDetection,args=(self.selectInterfaceStr,))
self.dhcpDetect = multiprocessing.Process(target=self.dhcpexhaustion,args=(self.selectInterfaceStr,))
self.camDetect.start()
self.dhcpDetect.start()

#intrusion signature 1
def camtableDetection(self,getInterface):
    global interface       
    interface = str(getInterface)
    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)):
                #self.liveDetectionResBox.AppendText('test')
                logfile = datetime.date.today()
                logging.basicConfig(filename="%s.log"%logfile,level=logging.DEBUG,format='%(asctime)s %(message)s',datefmt='%m/%d/%Y %I:%M:%S %p')
                logging.warning("- [Detected CAM Table Attack.]")

    hwList = []
    start = datetime.datetime.now()
    #try:
    sniff(iface=interface,prn=monitorPackets)
    #except:
        #networkDown = wx.MessageDialog(None,"Network is Down.\nMonitor on %s unable to start"%self.selectInterfaceStr,"",wx.OK|wx.ICON_ERROR)
        #networkDown.ShowModal()

Maybe a call to wx.Yield? See:
Werner

···

Hi,

  On 11/11/2013 08:24, Ku Wei Xiong wrote:

Dear all,

                  I am developing an intrusion detection system in

real time.Thus , i would like those result to be
appended to my textcontrol.However , i am unable
to append it.It is because the function run in
live(continuous) and append the textcontrol in
live.How can i solve this problem which any output
in real time be appended to my text control.I have
try the standard way but its does not appear in my
text control.

here is my code.

http://wiki.wxpython.org/LongRunningTasks

Not really sure how to use it with.still a novice here.

···

On Monday, 11 November 2013 15:24:20 UTC+8, Ku Wei Xiong wrote:

Dear all,

I am developing an intrusion detection system in real time.Thus , i would like those result to be appended to my textcontrol.However , i am unable to append it.It is because the function run in live(continuous) and append the textcontrol in live.How can i solve this problem which any output in real time be appended to my text control.I have try the standard way but its does not appear in my text control.

here is my code.

def startMonitor(self,event):
selectedInterface = self.interfaces_cblist.GetValue()
self.selectInterfaceStr = str(selectedInterface)
if len(selectedInterface) == 0:
noSelect_error = wx.MessageDialog(None,“Please select an interface”,“”,wx.OK|wx.ICON_ERROR)
noSelect_error.ShowModal()
else:
monitorStarted = wx.MessageDialog(None,“Monitor on %s started”%self.selectInterfaceStr,“”,wx.OK|wx.ICON_ERROR)
monitorStarted.ShowModal()
self.monitorInterface_button.Disable()
self.abortValue = 1;
self.camDetect = multiprocessing.Process(target=self.camtableDetection,args=(self.selectInterfaceStr,))
self.dhcpDetect = multiprocessing.Process(target=self.dhcpexhaustion,args=(self.selectInterfaceStr,))
self.camDetect.start()
self.dhcpDetect.start()

#intrusion signature 1
def camtableDetection(self,getInterface):
    global interface       
    interface = str(getInterface)
    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)):
                #self.liveDetectionResBox.AppendText('test')
                logfile = datetime.date.today()
                logging.basicConfig(filename="%s.log"%logfile,level=logging.DEBUG,format='%(asctime)s %(message)s',datefmt='%m/%d/%Y %I:%M:%S %p')
                logging.warning("- [Detected CAM Table Attack.]")


    hwList = []
    start = datetime.datetime.now()
    #try:
    sniff(iface=interface,prn=monitorPackets)
    #except:
        #networkDown = wx.MessageDialog(None,"Network is Down.\nMonitor on %s unable to start"%self.selectInterfaceStr,"",wx.OK|wx.ICON_ERROR)
        #networkDown.ShowModal()

Hi,

···

On 11/11/2013 09:56, Ku Wei Xiong wrote:

Not really sure how to use it with.still a novice here.

I never used multiprocessing nor threading, so take things with a grain of salt.

I would guess to put the wx.Yield call in the method where you update/append to the text control, it might also need a refresh.

Werner

There are some problems in the code you posted. Specifically, none
of it makes any reference to text controls at all. Show us the code
that manipulates the text control, and perhaps we can offer some
advice.
Note, however, that you cannot manipulate the text control from
outside the process that created the window. If you need to update
the UI from a multiprocessing function, you will have to use
something like wx.CallAfter to send a message back to the main
window.

···

Ku Wei Xiong wrote:

                  I am developing an intrusion detection system in

real time.Thus , i would like those result to be
appended to my textcontrol.However , i am unable
to append it.It is because the function run in
live(continuous) and append the textcontrol in
live.How can i solve this problem which any output
in real time be appended to my text control.I have
try the standard way but its does not appear in my
text control.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com