是否可以用 python 编写防火墙?

新手上路,请多包涵

是否可以用 python 编写防火墙?说它会阻止所有流量?

原文由 Jake 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 447
2 个回答

是的,是的。

我有一些使用 nfqueue 与 Linux iptables 交互以执行防火墙职责的 Python 代码。我可以在 iptables 中使用如下规则:

 iptables -A INPUT -j NFQUEUE --queue-num 1

然后有一些 Python 代码如下所示:

 import nfqueue
from dpkt import ip

q = None

def cb(dummy, payload):
    # make decision about if the packet should be allowed. in this case, drop everything:
    payload.set_verdict(nfqueue.NF_DROP)

q = nfqueue.queue()
q.open()
q.bind()
q.set_callback(cb)
q.create_queue(1)

q.try_run()

这是一篇很好的文章,上面的代码基于:

http://blog.yancomm.net/2011/05/nfqueue-packet-mangling-with-python.html

原文由 Jerub 发布,翻译遵循 CC BY-SA 3.0 许可协议

Python-iptables 为 Linux 下的 iptables 提供了 python 绑定。与 iptables 的互操作性是通过使用 iptables C 库(libiptc、libxtables 和 iptables 扩展)实现的,而不是调用 iptables 二进制文件并解析其输出。

http://ldx.github.io/python-iptables/index.html

原文由 Vincenzo 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏