2

Kindly guide me with the following problems.

Scapy version : 1 ( same result with current version 2 ) Os : Windows

Using the following program, the packets are taken into a queue in a child process using python multiprocessing module. Following are some observations.

  1. a.summary() doesnt show any results, a.show() works fine.
  2. the program gives an error after running for a couple of minutes. the error does not come when str(x) is put in the queue, where is x is the scapy packet class object. ( sample output is given below. )
  3. if "timeout" or "count" of sniff is given the Sniffme function blocks after its last instruction and does not join in with the main process.

=====PROGRAM STARTS HERE

from scapy import *
from multiprocessing import Process, Queue

def Sniffme(queue,N):
    print "Inside Sniffing"
    print "Queue size before sniff =",queue.qsize()
    sniff(iface="eth0", store=0, lfilter=lambda p: IP in p and p[IP].src != "192.168.1.30", prn= lambda x: queue.put(x, block=True, timeout=None))
    print "Sniffing Finished"
    print "Queue size after sniff =",queue.qsize()
    print "Process Exited!!!"

if __name__=="__main__":
    queue = Queue()
    N = 5  
    p = Process(target = Sniffme, args=(queue,N))
    p.start()
    print "Process Started!"
    #p.join()

    print "Queue size in parent process =",queue.qsize()
    while 1:
        #if queue.qsize():
        print "Inside While Loop"
        #print "Before", queue.qsize()
        a = queue.get()
        #print "After", queue.qsize()
        a.summary()

Sample output:

Process Started!
Process Finished!
Queue size in parent process = 0
Inside Sniffing

Queue size before sniff = 0
Inside While Loop
Inside While Loop
(.....)
Inside While Loop
Inside While Loop
Inside While Loop
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\multiprocessing\queues.py", line 238, in _feed
send(obj)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
Sniffing Finished
Queue size after sniff = 63
Process Exited!!!
Community
  • 1
  • 1
user1161599
  • 261
  • 1
  • 4
  • 17

0 Answers0