Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions bash/livedns/mywanip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Updates a zone record using Gandi's LiveDNS.
# Ideally this script is placed into a crontab or when the WAN interface comes up.
# Replace APIKEY with your Gandi API Key and DOMAIN with your domain name at Gandi.
# Set RECORD to which zone label you wish to update.
# You will be able to query mywanip.example.net if everything went successful.
# Set RECORDS to which zone labels you wish to update.
# You will be able to query example.net, mywanip.example.net and mywanip2.example.net if everything went successful.
#
# Live dns is available on www.gandi.net
# Obtaining your API Key: http://doc.livedns.gandi.net/#step-1-get-your-api-key
#

DOMAIN="example.net"
RECORD="mywanip"
RECORDS=( "@" "mywanip" "mywanip2" )
APIKEY="my-api-key"


Expand All @@ -27,19 +27,22 @@ if [[ -z "$IP4" && -z "$IP6" ]]; then
fi


if [[ ! -z "$IP4" ]]; then
DATA='{"rrset_values": ["'$IP4'"]}'
curl -s -XPUT -d "$DATA" \
-H"X-Api-Key: $APIKEY" \
-H"Content-Type: application/json" \
"$API/domains/$DOMAIN/records/$RECORD/A"
fi

if [[ ! -z "$IP6" ]]; then
DATA='{"rrset_values": ["'$IP6'"]}'
curl -s -XPUT -d "$DATA" \
-H"X-Api-Key: $APIKEY" \
-H"Content-Type: application/json" \
"$API/domains/$DOMAIN/records/$RECORD/AAAA"
fi
for RECORD in "${RECORDS[@]}"
do
if [[ ! -z "$IP4" ]]; then
DATA='{"rrset_values": ["'$IP4'"]}'
curl -s -XPUT -d "$DATA" \
-H"X-Api-Key: $APIKEY" \
-H"Content-Type: application/json" \
"$API/domains/$DOMAIN/records/$RECORD/A"
fi

if [[ ! -z "$IP6" ]]; then
DATA='{"rrset_values": ["'$IP6'"]}'
curl -s -XPUT -d "$DATA" \
-H"X-Api-Key: $APIKEY" \
-H"Content-Type: application/json" \
"$API/domains/$DOMAIN/records/$RECORD/AAAA"
fi
done