2015-01-18 11:25:05 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# This script is based on cf-ddns.sh found at
|
|
|
|
# <https://gist.github.com/larrybolt/6295160> and it's comments.
|
|
|
|
# Inspiration also took from
|
|
|
|
# <https://github.com/commx/ydns/blob/master/updater.sh> which is a lot
|
|
|
|
# more complex than this.
|
|
|
|
|
2015-01-18 11:31:18 +01:00
|
|
|
# yDNS details
|
|
|
|
USEREMAIL=""
|
|
|
|
PASSWORD=""
|
|
|
|
HOSTNAME=""
|
|
|
|
|
2015-01-18 11:25:05 +01:00
|
|
|
# Get IPv4 address
|
|
|
|
WAN_IP4=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
2015-01-18 11:36:44 +01:00
|
|
|
if [ -f $HOME/.wan_ip4-ydns.txt ]; then
|
2015-01-18 11:31:18 +01:00
|
|
|
OLD_WAN_IP4=$(cat $HOME/.wan_ip4-ydns.txt)
|
2015-01-18 11:25:05 +01:00
|
|
|
else
|
|
|
|
echo "No file, need IP4"
|
|
|
|
OLD_WAN_IP4=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get IPv6 address
|
|
|
|
WAN_IP6=$(dig +short myip.opendns.com AAAA @2620:0:ccc::2)
|
2015-01-18 11:31:18 +01:00
|
|
|
if [ -f $HOME/.wan_ip6-ydns.txt ]; then
|
|
|
|
OLD_WAN_IP6=$(cat $HOME/.wan_ip6-ydns.txt)
|
2015-01-18 11:25:05 +01:00
|
|
|
else
|
|
|
|
echo "No file, need IP6"
|
|
|
|
OLD_WAN_IP6=""
|
|
|
|
fi
|
|
|
|
|
2015-01-18 11:31:18 +01:00
|
|
|
# Update IPv4
|
|
|
|
if [ "$WAN_IP4" = "$OLD_WAN_IP4" ]; then
|
|
|
|
echo "IP4 Unchanged"
|
|
|
|
else
|
|
|
|
echo $WAN_IP4 > $HOME/.wan_ip4-ydns.txt
|
|
|
|
echo "Updating DNS to $WAN_IP4"
|
2015-01-18 11:32:20 +01:00
|
|
|
curl -4 --basic -u "$USEREMAIL:$PASSWORD" --silent \
|
|
|
|
https://ydns.eu/api/v1/update/?host=$HOSTNAME
|
2015-01-18 11:31:18 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Update IPv6
|
|
|
|
if [ "$WAN_IP6" = "$OLD_WAN_IP6" ]; then
|
|
|
|
echo "IP6 Unchanged"
|
|
|
|
else
|
|
|
|
echo $WAN_IP6 > $HOME/.wan_ip6-ydns.txt
|
|
|
|
echo "Updating DNS to $WAN_IP6"
|
2015-01-18 11:32:20 +01:00
|
|
|
curl -6 --basic -u "$USEREMAIL:$PASSWORD" --silent \
|
|
|
|
https://ydns.eu/api/v1/update/?host=$HOSTNAME
|
2015-01-18 11:31:18 +01:00
|
|
|
fi
|