Skip to main content

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. Daily automatic CIDR updates in the repository.

Compile CIDRs Publish Release to PyPI

asciicast


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

From PyPI

pip install cidre-cli

From Release

Download the latest precompiled binary from the Releases page:

chmod +x cidre && ./cidre

From Sources

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

Commands

cidr pull

Command Description
cidre cidr pull Fetches the latest IP allocation data from all RIRs
cidre cidr pull --merge Merges overlapping IP ranges for efficiency. Optional.
cidre cidr pull --proxy PROXY Proxies connection to RIRs. Optional.
cidre cidr pull --cidr-store PATH Specifies CIDRs' custom storage directory. Default: ./output/cidr

cidr count

Command Description
cidre cidr count Counts amount of IPs per country
cidre cidr count US CN Counts amount of IPs by country code (ISO 3166-1 alpha-2 code)
cidre cidr count --cidr-store PATH Specifies CIDRs' custom storage directory. Default: ./output/cidr

firewall allow|deny|reject

Command Description
cidre firewall allow Apply allow rule to specified firewall
cidre firewall deny Apply deny rule to specified firewall
cidre firewall reject Apply reject rule to specified firewall
cidre firewall reject --firewall ufw Firewall to apply rules. Options: ufw, iptables. Default: ufw
cidre firewall reject --cidr-store PATH Specifies CIDRs' custom storage directory. Default: ./output/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.

Metadata

Release files for cidre-cli 2.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cidre-cli 2.1.3
File Size Uploaded Provenance Actions
cidre_cli-2.1.3.tar.gz 10.9 kB Without provenance Details for cidre_cli-2.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cidre-cli 2.1.3
File Interpreter ABI Platform Actions
cidre_cli-2.1.3-py3-none-any.whl Python 3 none any Details for cidre_cli-2.1.3-py3-none-any.whl

Total release size: 23.0 kB

Release files / cidre_cli-2.1.3.tar.gz

Download URL cidre_cli-2.1.3.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9bc577905c61869d20fef83d2312d2277244a52c41f11d164fad0f3e1e1426f4
BLAKE2b-256 checksum
How to use checksums
def6c1957c60315530f80dc73a56049ae9c430722d5a39e24ce61e65edd72448
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / cidre_cli-2.1.3-py3-none-any.whl

Download URL cidre_cli-2.1.3-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b4ad0be4df8b5f1636ce35020296f47470d3d09920bfc51580c1a6a9ef519cc
BLAKE2b-256 checksum
How to use checksums
ea4e94d676ce9af0d5856f3f612378f0cbb09138d5f7a336a297113d1da4017f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Security for cidre-cli 2.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page