oremanj / python-netfilterqueue

Python bindings for libnetfilter_queue
MIT License
248 stars 96 forks source link

bind callback is not work #58

Closed unloadble closed 2 years ago

unloadble commented 4 years ago

hi guys i want to make a packet queue with this simple code :


from netfilterqueue import NetfilterQueue

def print_and_accept(pkt):
    print(pkt)

nfqueue = NetfilterQueue()
nfqueue.bind(0, print_and_accept)

but "print_and_accept" is not fire and work ! program doesnt print packet and internet is worked well ! how ? and how can fix it

slrendell commented 4 years ago

You need to accept the packet after you print it and you need to call run on nfqueue.

from netfilterqueue import NetfilterQueue

def print_and_accept(pkt):
    print(pkt)
    pkt.accept()

nfqueue = NetfilterQueue()
nfqueue.bind(0, print_and_accept)
nfqueue.run()

You also need to insert a rule in to iptables to queue the packets.

sudo iptables -I INPUT 1 -j NFQUEUE --queue-num 0

Remove the rule after with

sudo iptables -D INPUT 1

oremanj commented 2 years ago

Reply is correct, closing this since it hasn't seen any activity.