scripts/bash/deprecated/ydns-simple

64 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

#!/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 12:00:35 +01:00
# Basic usage (as root):
# curl -L https://github.com/Mikaela/scripts/raw/gh-pages/bash/ydns-simple > /usr/local/bin/ydns-simple
# chmod 700 /usr/local/bin/ydns-simple
## Copy-paste the following to your crontab without the #
# */5 * * * * /usr/local/bin/ydns-simple >/dev/null 2>&1
2015-01-18 11:31:18 +01:00
# yDNS details
USEREMAIL=""
PASSWORD=""
HOSTNAME=""
# Get IPv4 address
2024-06-06 19:59:19 +02:00
if hash dig 2> /dev/null; then
2023-04-06 11:03:10 +02:00
WAN_IP4=$(dig +short myip.opendns.com. A @208.67.220.220)
else
2023-04-06 11:03:10 +02:00
WAN_IP4=$(curl -sL4 https://icanhazip.com/)
fi
if [ -f $HOME/.wan_ip4-ydns.txt ]; then
2023-04-06 11:03:10 +02:00
OLD_WAN_IP4=$(cat $HOME/.wan_ip4-ydns.txt)
else
2023-04-06 11:03:10 +02:00
echo "No file, need IP4"
OLD_WAN_IP4=""
fi
# Get IPv6 address
2024-06-06 19:59:19 +02:00
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)
else
2023-04-06 11:03:10 +02:00
WAN_IP6=$(curl -sL6 https://icanhazip.com/)
fi
2015-01-18 11:31:18 +01:00
if [ -f $HOME/.wan_ip6-ydns.txt ]; then
2023-04-06 11:03:10 +02:00
OLD_WAN_IP6=$(cat $HOME/.wan_ip6-ydns.txt)
else
2023-04-06 11:03:10 +02:00
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
2023-04-06 11:03:10 +02:00
echo "IP4 Unchanged"
2015-01-18 11:31:18 +01:00
else
2024-06-06 19:59:19 +02:00
echo $WAN_IP4 > $HOME/.wan_ip4-ydns.txt
2023-04-06 11:03:10 +02:00
echo "Updating DNS to $WAN_IP4"
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
2023-04-06 11:03:10 +02:00
echo "IP6 Unchanged"
2015-01-18 11:31:18 +01:00
else
2024-06-06 19:59:19 +02:00
echo $WAN_IP6 > $HOME/.wan_ip6-ydns.txt
2023-04-06 11:03:10 +02:00
echo "Updating DNS to $WAN_IP6"
curl -6 --basic -u "$USEREMAIL:$PASSWORD" --silent \
https://ydns.eu/api/v1/update/?host=$HOSTNAME
2015-01-18 11:31:18 +01:00
fi