-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmywanip.sh
45 lines (36 loc) · 1.24 KB
/
mywanip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#
# 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.
#
# 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"
APIKEY="my-api-key"
API="https://dns.api.gandi.net/api/v5/"
IP_SERVICE="http://me.gandi.net"
IP4=$(curl -s4 $IP_SERVICE)
IP6=$(curl -s6 $IP_SERVICE)
if [[ -z "$IP4" && -z "$IP6" ]]; then
echo "Something went wrong. Can not get your IP from $IP_SERVICE "
exit 1
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