您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

是的,是的。

我有一些Python代码,可以使用nfqueue与Linux iptables交互以执行防火墙职责。我可以在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

python 2022/1/1 18:42:20 有476人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶