Skip to main content

A CLI tool for fetching and managing CIDR IP ranges from RIRs with firewall integration.

Project description

CIDRE

CIDRe is a CLI tool that fetches daily updated IP allocations from Regional Internet Registries (RIRs), compiles them into country-based CIDR files, and allows easy firewall management.

Compile CIDRs Publish Release to PyPI

demo

🔹 Supports AFRINIC, APNIC, ARIN, LACNIC, RIPE NCC
🔹 Daily automatic CIDR updates in the repository
🔹 Merges and optimizes CIDR blocks for efficiency
🔹 Firewall integration (UFW & iptables /w ipset support)
🔹 IPv4 & IPv6 compatible


⚡ Quick start

Install CIDRE

pip install cidre-cli

Pull & merge CIDR ranges

cidre cidr pull --merge
  • Downloads the latest CIDR allocations from RIRs.
  • Merges overlapping IP ranges for efficiency.

Block specific countries

# UFW is better suited for small CIDR inputs
cidre firewall deny ir kp --firewall ufw
  • Blocks Iran (IR), and North Korea (KP) in UFW.
  • Requires ufw installed (sudo apt install ufw).
# iptables is better suited for large CIDR inputs
cidre firewall deny ru ir kp --firewall iptables
  • Blocks Russia (RU), Iran (IR), and North Korea (KP) in iptables using ipset.
  • Requires ipset and iptables installed (sudo apt install ipset iptables).

🛠️ Installation

Install via PyPI

pip install cidre-cli

Alternative: clone the repository

git clone https://github.com/vulnebify/cidre.git
cd cidre
python3 -m venv .venv
source .venv/bin/activate
pip install .

⚡ Usage

Pull and compile CIDR ranges

Fetches the latest IP allocation data from all RIRs and compiles per-country CIDR blocks:

cidre cidr pull --merge
  • --merge: Merges overlapping IP ranges for efficiency.
  • --proxy <proxy>: Proxies connection to RIRs.
  • --cidr-store <path>: Specifies CIDRs' custom storage directory. Default ./output/cidr/{ipv4|ipv6}/{country_code}.cidr.

Action on countries

Allow|deny|reject specific countries' CIDR blocks in specified firewall:

cidre firewall allow|deny|reject ru ir kp
  • --firewall ufw|iptables: Firewall to apply rules. Default ufw.
  • --cidr-store <path>: Specifies CIDRs' custom storage directory. Default ./output/cidr/{ipv4|ipv6}/{country_code}.cidr.

⚠️ NOTE: iptables firewall DO NOT persist rules by default

To ensure iptables and IPSet rules persist after a reboot, follow these steps:

# Save rules based on the firewall method:
# - For iptables + IPSet:
sudo ipset save > /etc/ipset.rules
sudo iptables-save > /etc/iptables/rules.v4
sudo ip6tables-save > /etc/iptables/rules.v6

# Restore firewall rules on boot:
# - For iptables + IPSet:
sudo bash -c 'echo "ipset restore < /etc/ipset.rules" >> /etc/rc.local'
sudo chmod +x /etc/rc.local

# Reboot and verify:
sudo reboot
sudo ipset list
sudo iptables -L -v -n

📄 License

This project is licensed under the MIT License.


🙌 Inspired by

CIDRE was inspired by herrbischoff/country-ip-blocks and aims to provide an automated alternative with firewall integration.


🤝 Contributions

PRs are welcome! Feel free to fork the repo and submit pull requests.


📧 Contact

For any questions, open an issue or reach out via GitHub Discussions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cidre_cli-2.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cidre_cli-2.0.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file cidre_cli-2.0.0.tar.gz.

File metadata

  • Download URL: cidre_cli-2.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for cidre_cli-2.0.0.tar.gz
Algorithm Hash digest
SHA256 46a78296ddeab69caae093839cc5b8509b90da941c0b7ff564f91f2c1b63b7dd
MD5 5544d5eed1381dd86ed1fb6b2754ac3b
BLAKE2b-256 d1e7481d1943449c898f95d69495c83ada6a79bf7e1127eed83076de2877e806

See more details on using hashes here.

File details

Details for the file cidre_cli-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: cidre_cli-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for cidre_cli-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cb998eb2cdfd4813c5bc955206fd1ad947cc56e9e5f8945d019e60797a891ba
MD5 5683c188a3b6eea6a07807c6f0fbe8b3
BLAKE2b-256 41895031b95730ef5c95320de33eaa871cd1a8506be7e84915f5134395b3ef7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page