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"
Metadata
Release files for google-dns-ips 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| google_dns_ips-0.1.0.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| google_dns_ips-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / google_dns_ips-0.1.0.tar.gz
| Download URL | google_dns_ips-0.1.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06f8ab45196647564d093414fcaa0928f9d0b9c196c30ff5ac78e69b1e0af7bb
|
|
BLAKE2b-256 checksum How to use checksums |
f5a3dc0fdd8c56200e19fe0f803edcbb6ba7dfc42b27f534493bdea255bc558d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / google_dns_ips-0.1.0-py3-none-any.whl
| Download URL | google_dns_ips-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ce14c624680de594302e1ee25c8fc9ef14dbd02d6c764ccddbf4b766021e05b
|
|
BLAKE2b-256 checksum How to use checksums |
29617681fb9d9a9caeab1148e913dd7a66067ed51130b380cb7f558f88275a8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|