Skip to content

Instantly share code, notes, and snippets.

@jcarley
Forked from voxxit/digitalocean-dyndns
Last active August 29, 2015 14:22
Show Gist options
  • Save jcarley/1cd960b7d1dd6764f751 to your computer and use it in GitHub Desktop.
Save jcarley/1cd960b7d1dd6764f751 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -x
# Domain you wish to update
DOMAIN="example.com"
# Get the v4/v6 addresses from icanhazip.com [pretty reliable!]
IPV4_ADDR=`wget -4 -q -O - icanhazip.com`
IPV6_ADDR=`wget -6 -q -O - icanhazip.com`
# Get your v2 API token from here: https://cloud.digitalocean.com/settings/tokens/new
TOKEN="..."
# Add the record IDs you wish to update here
V4_RECORDS=(123 ...)
V6_RECORDS=(678 ...)
for RECORD in $V4_RECORDS
do
wget \
-O - \
--quiet \
--no-check-certificate \
--method="PUT" \
--header="Content-Type: application/json" \
--header="Authorization: Bearer $TOKEN" \
--body-data="{\"data\":\"$IPV4_ADDR\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD"
done
for RECORD in $V6_RECORDS
do
wget \
-O - \
--quiet \
--no-check-certificate \
--method="PUT" \
--header="Content-Type: application/json" \
--header="Authorization: Bearer $TOKEN" \
--body-data="{\"data\":\"$IPV6_ADDR\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment