cloudflare-dns
CLI and Python tool for managing Cloudflare DNS
https://github.com/ZigZagT/cloudflare-dns
Installation
pip install cloudflare-dns
Usage
usage: cloudflare-dns [-h] [--ignore-api-error] [-z ZONE] [-e EMAIL] [-k KEY] [-t TOKEN] (-lz | -lr | -sr | -dr) [--filter-content REGEX] [--proxied] [{A,AAAA,CNAME,TXT,ANY}] [domain] [content] [ttl]
options:
-h, --help show this help message and exit
--ignore-api-error treat 5xx API responses as success
-lz, --list-zone [action] list zones, record frags and filters are ignored for this action
-lr, --list-record [action] list DNS records in a zone, record frags are used as filters when provided
-sr, --set-record [action] create or update DNS record to match record frags, removes any existing records that matches the [type, domain] tuple; use the filters to limit the removing to matching records only
-dr, --delete-record [action] delete DNS record base on provided record frags and filters
authentication arguments:
-z ZONE, --zone ZONE specify the zone by its domain name, usually can be inferred from the domain parameter
-e EMAIL, --email EMAIL
default to environment variable CF_API_EMAIL
-k KEY, --key KEY default to environment variable CF_API_KEY
-t TOKEN, --token TOKEN
default to environment variable CF_API_TOKEN. Note the use of api token is exclusive, --email and --key must not be used when --token is used.
filtering arguments:
scope operations of changing / removing records by the filters
--filter-content REGEX
filter records by matching their content against the provided regex.
record frags:
use record frags to describes a single DNS record, may freely provide from 0 to all 5 frags, as long as it makes sense to the chosen action
{A,AAAA,CNAME,TXT,ANY}
record type, ANY is only valid for filtering
domain full qualified domain name
content the content of the record
ttl ttl value of 1 means auto on Cloudflare; ignored for -lr and -dr
--proxied set cloudflare proxy on/off state; ignored for -lr and -dr
Examples of typical Usages
Dynamic DNS (DDNS)
IP=$(curl -sL https://ipinfo.io/ip)
cloudflare-dns -sr A dev.example.com $IP
cloudflare-dns -sr A www.example.com $IP --proxied
cloudflare-dns -sr A long-dns-ttl.example.com $IP 36000 --proxied
Show all TXT records at root domain
cloudflare-dns -lr TXT example.com
# records:
# -------------------------------------------------------------------------------
# id: aaaa
# type: TXT
# name: example.com
# content: google-site-verification=aaaa
# ttl: 1
# proxiable: False
# proxied: False
# locked: False
# -------------------------------------------------------------------------------
# id: bbbb
# type: TXT
# name: example.com
# content: v=spf1 include:_spf.google.com ~all
# ttl: 1
# proxiable: False
# proxied: False
# locked: False
# -------------------------------------------------------------------------------
Show SPF TXT record at root domain
cloudflare-dns -lr TXT example.com --filter-content v=spf1
# records:
# -------------------------------------------------------------------------------
# id: bbbb
# type: TXT
# name: example.com
# content: v=spf1 include:_spf.google.com ~all
# ttl: 1
# proxiable: False
# proxied: False
# locked: False
# -------------------------------------------------------------------------------
Update a SPF TXT records at root domain
cloudflare-dns -sr TXT example.com 'v=spf1 include:_spf.google.com ~all' --filter-content v=spf1
# UNCHANGED: example.com v=spf1 include:_spf.google.com ~all
Batch update DMARC records for multiple sites
for domain in $(cat my_domains.txt); do
cloudflare-dns -sr --filter-content v=DMARC1 \
TXT \
_dmarc.$domain \
"v=DMARC1; p=quarantine; fo=0:1:d:s; rua=mailto:dmarc@$domain; ruf=mailto:dmarc@$domain; aspf=r; adkim=s;" \
3600
done
How to authenticate with the Cloudflare API:
# option 1: by using environment variables
export CF_API_EMAIL="<my cloudflare email>"
export CF_API_KEY="<my cloudflare api key>"
cloudflare-dns -sr A dev.example.com $IP
# option 2: via command line parameters
cloudflare-dns -e $MY_EMAIL -k $MY_KEY -sr A dev.example.com $IP
Metadata
Release files for cloudflare-dns 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cloudflare_dns-1.3.1.tar.gz | 15.6 kB | Without provenance | Details for cloudflare_dns-1.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cloudflare_dns-1.3.1-py3-none-any.whl | Python 3 | none | any | Details for cloudflare_dns-1.3.1-py3-none-any.whl |
Total release size: 23.1 kB
Release files / cloudflare_dns-1.3.1.tar.gz
| Download URL | cloudflare_dns-1.3.1.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cde6767c0d472d9a63a702d729b9830ac41f9348d59799cc6e76cd49b2ad42e2
|
|
BLAKE2b-256 checksum How to use checksums |
9a26f6f31c3d48524a972febb5ef4b811c1b8b8dc28d50078247f700e4098f19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / cloudflare_dns-1.3.1-py3-none-any.whl
| Download URL | cloudflare_dns-1.3.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d594e724507fc317e3edb565d1d0d49aa0712280e1665a2455197c3a17a1a9ce
|
|
BLAKE2b-256 checksum How to use checksums |
0962b22aa4646572ca3f7f258b17a2e18b075468b35889c98163e8fa2a4fd300
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for cloudflare-dns 1.3.1
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.