【问题标题】:iptables v 1.8.4v(legacy): unknown option --string [duplicate]iptables v 1.8.4v(旧版):未知选项--string [重复]
【发布时间】:2021-05-28 09:19:24
【问题描述】:

这是我用于调用 IPtables 的 python 脚本,我需要 SQLite 输出来制定规则 (df2)

subprocess.run(["/usr/sbin/iptables", "-A", "INPUT", "-p", "udp", "-m", "udp", "--dport 5060", "-m" "string",
                "--string" , "/home/as/Documents/mydf.csv", "-algo", "bm", "--to 655535", "-j" ,"REJECT"])

我遇到的错误

iptables v 1.8.4v(legacy): unknown option  --string

【问题讨论】:

  • "-algo bm" 需要是两个字符串:"-algo", "bm"。与"--to 65535" 相同。 iptables 的路径错误,所以这不是你的确切代码。
  • ...和"--dport 5060"
  • @TimRoberts 我也试过分离所有的字符串,但没有运气,也请你告诉我如何写路径位置,我写路径为subprocess.call(["/usr/sbin/iptables"(iptable file location),..(all the middle strings separated by " ")....,"/home/Documents/.csv(file location)"])
  • @larsks 我尝试分离所有字符串
  • 我的意思是,在您问题的示例中,您的“usr/bin/iptables”没有前导斜杠。您是否安装了 iptables-string 扩展?为什么在 Linux 系统中使用 Windows 文件路径?

标签: python bash subprocess iptables


【解决方案1】:

在您在答案中发布的代码中,usr/sbin/iptables 没有前导斜杠。你应该使用/usr/sbin/iptables

在对subprocess.run() 的调用中还有几个部分需要将参数分隔为单独的列表项。您还忘记了"-m""string" 之间的逗号。

试试这个:

subprocess.run([
    "/usr/sbin/iptables",
    "-A", "INPUT",
    "-p", "udp",
    "-m", "udp",
    "--dport", "5060",
    "-m", "string",
    "--string", "insert csv file location here",
    "-algo", "bm",
    "--to", "655535",
    "-j", "REJECT",
])

【讨论】:

  • 嗨,仍然遇到同样的错误iptables v 1.8.4v(legacy): no command specified
  • 那么问题可能出在您的iptables 命令上,而不是您的python 代码上。
  • 嗨,另一个错误iptables v 1.8.4v(legacy): unknown option "--string"
猜你喜欢
  • 1970-01-01
  • 2014-09-23
  • 2012-04-05
  • 2021-04-12
  • 2016-03-19
  • 2013-04-28
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
相关资源
最近更新 更多