Resolve Google IP CIDR ranges from published DNS TXT records
Project description
google-dns-ips
Python library that resolves Google-published IP ranges from DNS TXT records.
It parses SPF-style TXT records (including nested include: records) and extracts
all ip4: and ip6: CIDRs.
Why DNS TXT?
Google publishes network ranges in DNS TXT records such as:
_netblocks.google.com_netblocks2.google.com_netblocks3.google.com_spf.google.com_cloud-netblocks.googleusercontent.com
This package also resolves host records (A/AAAA), by default dns.google,
and includes those addresses as /32 or /128 networks.
This library recursively walks those records and returns normalized ranges.
Install
From the project root:
pip install -e .
Library Usage
from google_dns_ips import GoogleIPQuery, get_google_ip_cidrs
result = get_google_ip_cidrs()
query = GoogleIPQuery.from_cidrs(result.cidrs)
print(query.contains("8.8.8.8"))
print(query.collides("8.8.8.0/24"))
print(query.contains("8.8.0.0-8.8.255.255"))
result is a ResolutionResult with:
cidrs: sorted tuple of unique CIDR stringsvisited_records: sorted tuple of DNS names visited during recursion
GoogleIPQuery 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_google_ips.py
Flask JSON Server Example
Run:
python examples/flask_server.py
All endpoints return JSON.
Examples:
curl "http://127.0.0.1:5001/health"
curl "http://127.0.0.1:5001/metadata"
curl "http://127.0.0.1:5001/cidrs"
curl "http://127.0.0.1:5001/networks"
curl "http://127.0.0.1:5001/check?value=8.8.8.8"
curl "http://127.0.0.1:5001/check?value=8.8.8.0/24"
curl "http://127.0.0.1:5001/check?value=8.8.0.0-8.8.255.255"
curl "http://127.0.0.1:5001/check/range?start=8.8.8.0&end=8.8.8.255"
Full Endpoint List (127.0.0.1)
Base URL:
http://127.0.0.1:5001
GET /health
curl "http://127.0.0.1:5001/health"
GET /metadata
curl "http://127.0.0.1:5001/metadata"
GET /cidrs
curl "http://127.0.0.1:5001/cidrs"
GET /networks
curl "http://127.0.0.1:5001/networks"
GET /checkwith required query paramvalue
IP examples:
curl "http://127.0.0.1:5001/check?value=8.8.8.8"
curl "http://127.0.0.1:5001/check?value=2001:4860:4860::8888"
CIDR examples:
curl "http://127.0.0.1:5001/check?value=8.8.8.0/24"
curl "http://127.0.0.1:5001/check?value=2001:4860:4860::/48"
Range examples (start-end):
curl "http://127.0.0.1:5001/check?value=8.8.0.0-8.8.255.255"
curl "http://127.0.0.1:5001/check?value=2001:4860:4860::8888-2001:4860:4860::8899"
Error examples:
curl "http://127.0.0.1:5001/check"
curl "http://127.0.0.1:5001/check?value=not-an-ip"
curl "http://127.0.0.1:5001/check?value=1.1.1.1-2001:4860:4860::8888"
GET /check/rangewith required query paramsstartandend
IPv4 range examples:
curl "http://127.0.0.1:5001/check/range?start=8.8.8.0&end=8.8.8.255"
curl "http://127.0.0.1:5001/check/range?start=8.8.8.255&end=8.8.8.0"
IPv6 range example:
curl "http://127.0.0.1:5001/check/range?start=2001:4860:4860::8888&end=2001:4860:4860::8899"
Error examples:
curl "http://127.0.0.1:5001/check/range"
curl "http://127.0.0.1:5001/check/range?start=8.8.8.8"
curl "http://127.0.0.1:5001/check/range?start=8.8.8.8&end=2001:4860:4860::8888"
curl "http://127.0.0.1:5001/check/range?start=bad&end=input"
GETunknown route (JSON 404)
curl "http://127.0.0.1:5001/not-found"
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 google_dns_ips-0.1.0.tar.gz.
File metadata
- Download URL: google_dns_ips-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06f8ab45196647564d093414fcaa0928f9d0b9c196c30ff5ac78e69b1e0af7bb
|
|
| MD5 |
e3d01e2091c1dbb01b33317be665f8ef
|
|
| BLAKE2b-256 |
f5a3dc0fdd8c56200e19fe0f803edcbb6ba7dfc42b27f534493bdea255bc558d
|
File details
Details for the file google_dns_ips-0.1.0-py3-none-any.whl.
File metadata
- Download URL: google_dns_ips-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 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 |
4ce14c624680de594302e1ee25c8fc9ef14dbd02d6c764ccddbf4b766021e05b
|
|
| MD5 |
501454c3c55a94f54191c5ec3814d59f
|
|
| BLAKE2b-256 |
29617681fb9d9a9caeab1148e913dd7a66067ed51130b380cb7f558f88275a8b
|