Skip to main content

CLI and Python tool for managing Cloudflare DNS

Project description

cloudflare-dns

CLI and Python tool for managing Cloudflare DNS

https://github.com/ZigZagT/cloudflare-dns

PyPI - Python Version

Installation

pip install cloudflare-dns

Usage

cloudflare-dns -h
usage: cloudflare-dns [-h] [-z ZONE] [-e EMAIL] [-k KEY] [-t TOKEN] (-lz | -lr | -sr | -dr) [--filter-content REGEX] [--proxied] [{A,AAAA,CNAME,TXT,ANY}] [domain] [content] [ttl]

optional arguments:
  -h, --help            show this help message and exit
  -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

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

cloudflare-dns-1.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

cloudflare_dns-1.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file cloudflare-dns-1.2.0.tar.gz.

File metadata

  • Download URL: cloudflare-dns-1.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.6

File hashes

Hashes for cloudflare-dns-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d4ca1ca7463e885bec9a3731f82382839c523e10ff4d10c53e9ed98df4a273e4
MD5 128267fb257468cf7703ecd975f24f7f
BLAKE2b-256 2cb7b0b72558e17795089ec44c55e0eb0bf9e3d2aaa2cd258821fad97dcb75db

See more details on using hashes here.

Provenance

File details

Details for the file cloudflare_dns-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudflare_dns-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25c8bd6b49f3bf73df3d0e6d1436d9dfb9bd9e7c76bb184848cb8da21ee15679
MD5 949a59feabd7ebba36d772a705d5108c
BLAKE2b-256 af78630556cc748447b19cf210276a0a94deeb036484de97c339fc14723729c2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page