Resolve Cloudflare IP CIDR ranges from the authoritative published JSON source
Project description
cloudflare-json-ips
Python library that resolves Cloudflare-published IP ranges from the authoritative JSON source.
It downloads and parses https://api.cloudflare.com/client/v4/ips, extracts
all IPv4 and IPv6 CIDRs, and provides helpers for containment and overlap queries.
Why JSON?
Cloudflare publishes an authoritative machine-readable API response with:
result.ipv4_cidrsresult.ipv6_cidrsresult.etag
This package reads that source directly.
Install
From PyPI
pip install cloudflare-json-ips
Local Development
From the project root:
pip install -e .
Library Usage
from cloudflare_json_ips import CloudflareIPQuery, get_cloudflare_ip_cidrs
result = get_cloudflare_ip_cidrs()
query = CloudflareIPQuery.from_cidrs(result.cidrs)
print(result.etag)
print(query.contains("104.16.0.0/13"))
print(query.collides("104.16.0.0-104.23.255.255"))
result is a ResolutionResult with:
cidrs: sorted tuple of unique CIDR stringsetag: source etag from Cloudflare's responsesource_url: JSON URL usedselected_prefix_count: number of selected IPv4 and IPv6 prefix entries
CloudflareIPQuery supports:
contains(value): full containment for IP, CIDR, or range string (start-end)collides(value): any overlap for IP, CIDR, or range string (start-end)- Specific methods:
contains_ip,contains_cidr,contains_range,collides_ip,collides_cidr,collides_range
Example Script
Run:
python examples/print_cloudflare_ips.py
Flask JSON Server Example
Run:
python examples/flask_server.py
All endpoints return JSON.
Examples:
curl "http://127.0.0.1:5003/health"
curl "http://127.0.0.1:5003/metadata"
curl "http://127.0.0.1:5003/cidrs"
curl "http://127.0.0.1:5003/networks"
curl "http://127.0.0.1:5003/check?value=104.16.0.0/13"
curl "http://127.0.0.1:5003/check?value=104.16.0.0-104.23.255.255"
curl "http://127.0.0.1:5003/check/range?start=104.16.0.0&end=104.23.255.255"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloudflare_json_ips-0.1.0.tar.gz.
File metadata
- Download URL: cloudflare_json_ips-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33abb1ba878c768f03cbda449b2d5612871279110da140d0a45658b8197fc995
|
|
| MD5 |
06d1af1eb20ddc0839f24a82a37a8218
|
|
| BLAKE2b-256 |
d8f47b57bf7de7f4f44763c2dac0b5e58ac7e5d66cdec2cbf74aa992110c12d8
|
File details
Details for the file cloudflare_json_ips-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cloudflare_json_ips-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8cc4f27e68bb0b0b1c4b12cc0f62fa937e1a545eb7462abda78feed56fcd692
|
|
| MD5 |
98a348aa0448077b9f169eb4d229b335
|
|
| BLAKE2b-256 |
51ca886583a3afad27a375b6c29778e3e1534662bd3067bb4628e84248cbc102
|