Is it possible to write a firewall in python?

后端 未结 6 1043
深忆病人
深忆病人 2020-12-28 21:27

Is it possible to write a firewall in python? Say it would block all traffic?

6条回答
  •  孤城傲影
    2020-12-28 21:36

    Interesting thread. I stumbled on it looking for Python NFQUEUE examples.

    My take is you could create a great firewall in python and use the kernel.

    E.g. Add a linux fw rule through IP tables that forward sys packets (the first) to NFQUEUE for python FW to decide what to do.

    If you like it mark the tcp stream/flow with a FW mark using NFQUEUE and then have an iptables rule that just allows all traffic streams with the mark.

    This way you can have a powerful high-level python program deciding to allow or deny traffic, and the speed of the kernel to forward all other packets in the same flow.

提交回复
热议问题