pythonnestedpython-multiprocessingscapysniffing

Strange sytax error with nested keyword parameters


I am currently trying to code some sort of QoS box by utilizing MITM via ARP poisioning. Now I ran into a syntax error I can not seem to resolve:

File "/home/pi/qosmitm/networker.py", line 53
self.recv_threads.append(multiprocessing.Process(target=sniff, args=(iface=interface,
                                                                          ^ SyntaxError: invalid syntax

The Code:

    for i in range(0, len(net_map[0])):
            ip = net_map[0][i]
            mac = net_map[1][i]
            self.packet_queues.append(multiprocessing.Queue())
            self.recv_threads.append(multiprocessing.Process(target=sniff, args=(iface=interface, filter='host ' + ip, prn=mitm.recv_packets(self.packet_queues[i]))))

interface is a string.

And here is the recv_packets funktion:

def recv_packets(self, queue): # not too sure bout that
    def recv_packets(self, pkt):
        # flip macs & put into queue
        old_src = pkt[Ether].src
        print(pkt.summary())
        pkt[Ether].src = pkt[Ether].dst
        pkt[Ether].dst = old_src                                                                          queue.put(pkt)

I checked the different docs but I could not find out what I am doing wrong. My guess is that it is somehow related to the nested function calls/callbacks(?).

Thanks in advance!


Solution

  • Thanks @jasonharper for clearifying this. Read his comment below my question for an explanation to this corrected code snipped.

    self.recv_threads.append(multiprocessing.Process(target=sniff, args={'iface':interface, filter':'host ' + ip, 'prn':mitm.recv_packets(self.packet_queues[i])})
    

    Go drop him an upvote for the quick answer. Much appreciated!