推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
mactaew
V2EX  ›  Python

请教 Python 如何控制 firewalld

  •  
  •   mactaew · Feb 20, 2024 · 3922 views
    This topic created in 955 days ago, the information mentioned may be changed or developed.

    以前自己写了一个 sh 脚本,最近在学 Python ,想把这个脚本重新写一遍。

    脚本中有一块功能是通过执行 firewall-cmd --direct 直接写入 iptables 语句的,目前就不知道通过 Python 有没有更好方式来实现这个功能,控制端口的开放和关闭。

    特此请教!还请有经验的大大指导!!

    6 replies  •  2024-02-20 13:31:47 +08:00
    deorth
        1
    deorth  
       Feb 20, 2024 via Android
    找个 netfilter 的包,直接 call c api
    NoOneNoBody
        2
    NoOneNoBody  
       Feb 20, 2024
    只要不是需要返回执行结果给 python ,那都是容易的,搜搜"python 如何执行外部命令"
    alexsz
        3
    alexsz  
       Feb 20, 2024   ❤️ 1
    subprocess
    Trim21
        4
    Trim21  
       Feb 20, 2024 via Android
    @NoOneNoBody 想要拿 stdout 和 stderr 也不难
    jayeli
        5
    jayeli  
       Feb 20, 2024
    firewalld 本省就是一个 python 模块,你熟悉的话可以直接 import ,不熟悉的话就用 subprocess
    pingdog
        6
    pingdog  
       Feb 20, 2024 via Android
    看 fail2ban 操控 firewalld 的马
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2592 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 13:33 · PVG 21:33 · LAX 06:33 · JFK 09:33
    ♥ Do have faith in what you're doing.