我正在用python创建一个向iptables添加规则的程序 使用库python-iptables
这是我的代码
import iptc
rule = iptc.Rule()
rule.protocol = "tcp"
rule.target = iptc.Target(rule, "ACCEPT")
match = iptc.Match(rule, "state")
# i need to be root user here in order to call the FILTER method
chain = iptc.Chain(iptc.Table(iptc.Table.FILTER), "INPUT")
match.state = "RELATED,ESTABLISHED,FOOBAR"
rule.add_match(match)
chain.insert_rule(rule)
# then back to regular user after the insert rule
# ``` other code goes here ```
我该如何实施? PS。我希望完全自动化,不会提示密码。 我尝试了其他解决方案,但无法使其正常工作。