V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 67 天前 · 1230 次点击
    这是一个创建于 67 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    6 条回复    2024-02-20 13:31:47 +08:00
    deorth
        1
    deorth  
       67 天前 via Android
    找个 netfilter 的包,直接 call c api
    NoOneNoBody
        2
    NoOneNoBody  
       67 天前
    只要不是需要返回执行结果给 python ,那都是容易的,搜搜"python 如何执行外部命令"
    alexsz
        3
    alexsz  
       67 天前   ❤️ 1
    subprocess
    Trim21
        4
    Trim21  
       67 天前 via Android
    @NoOneNoBody 想要拿 stdout 和 stderr 也不难
    jayeli
        5
    jayeli  
       67 天前
    firewalld 本省就是一个 python 模块,你熟悉的话可以直接 import ,不熟悉的话就用 subprocess
    fuzzsh
        6
    fuzzsh  
       67 天前 via Android
    看 fail2ban 操控 firewalld 的马
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:53 · PVG 02:53 · LAX 11:53 · JFK 14:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.