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. 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

Install from PyPI

pip install cidre-cli

Intall from GitHub

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.

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.1.1.tar.gz (10.9 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.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cidre_cli-2.1.1.tar.gz
  • Upload date:
  • Size: 10.9 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.1.1.tar.gz
Algorithm Hash digest
SHA256 b5f01a0c53feaf871ca5e9045a03798fea1baab443727e79c543fab567f6070b
MD5 1958bb4ea8d7fde83faca3413aa04d0f
BLAKE2b-256 aa8b2d1d20c1998a2ec106445c934c7171365b08cf8f22861834ddfd82654502

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cidre_cli-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3b3875c206187797f5222c531cf0523f500360cfb3330794a5c0963755afc65
MD5 2e0e043ddcf9f68e9c86ccb2d3c99470
BLAKE2b-256 84270641e4eb8a1afa9807005ae47a60ec841e6cf23b682a08ce9604f5fc4a70

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