scripts/bash/deprecated/ydns6

46 lines
1.3 KiB
Plaintext
Raw Normal View History

2015-12-25 08:33:46 +01:00
#!/usr/bin/env bash
# This script deprecates ydns6 which does dualstack and which I won't
# be updating anymore as IPv4 is always behind NAT and thus useless to me.
# 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.
# Basic usage:
# mkdir -p ~/.local/bin
# curl -L https://github.com/Mikaela/scripts/raw/gh-pages/bash/ydns6 > ~/.local/bin/ydns6
# chmod 700 ~/.local/bin/ydns6
## Copy-paste the following to your crontab without the #
# */5 * * * * PATH_TO_HOME_DIRECTORY_HERE/.local/bin/ydns6 >/dev/null 2>&1
# yDNS details
USEREMAIL=""
PASSWORD=""
HOSTNAME=""
# Get IPv6 address
if hash dig 2>/dev/null; then
2023-04-06 11:03:10 +02:00
WAN_IP6=$(dig +short myip.opendns.com. AAAA @2620:0:ccd::2)
2015-12-25 08:33:46 +01:00
else
2023-04-06 11:03:10 +02:00
WAN_IP6=$(curl -sL6 https://icanhazip.com/)
2015-12-25 08:33:46 +01:00
fi
2015-12-25 08:44:24 +01:00
if [ -f $HOME/.ydns6.txt ]; then
2023-04-06 11:03:10 +02:00
OLD_WAN_IP6=$(cat $HOME/.ydns6.txt)
2015-12-25 08:33:46 +01:00
else
2023-04-06 11:03:10 +02:00
echo "No file, need IP6"
OLD_WAN_IP6=""
2015-12-25 08:33:46 +01:00
fi
# Update IPv6
if [ "$WAN_IP6" = "$OLD_WAN_IP6" ]; then
2023-04-06 11:03:10 +02:00
echo "IP6 Unchanged"
2015-12-25 08:33:46 +01:00
else
2023-05-18 11:25:47 +02:00
echo $WAN_IP6 >$HOME/.ydns6.txt
2023-04-06 11:03:10 +02:00
echo "Updating DNS to $WAN_IP6"
curl -6 --basic -u "$USEREMAIL:$PASSWORD" --silent \
https://ydns.io/api/v1/update/?host=$HOSTNAME\&ip=$WAN_IP6
2015-12-25 08:33:46 +01:00
fi