Python bindings for iptables, providing a Pythonic interface to manipulate Linux netfilter rules. Currently at v1.2.0, with infrequent releases and limited maintenance.
pip install python-iptablesVerified import paths — ran on the pinned version, not inferred.
List all rules in the FILTER table. Run as root.
Run script with sudo or set capabilities on Python interpreter.
Use python-nftables or subprocess calls to iptables-legacy.
After modifying rules/flushing chain, call table.commit().
Run with sudo: sudo python script.py
Use 'from iptc import Table' instead of 'import iptables'.
Ensure chain exists (e.g., from table.chains) or create chain first.