Created
February 7, 2025 09:50
-
-
Save azlux/310e4a8a1288e7c39d0a9462f34499e6 to your computer and use it in GitHub Desktop.
OVH DynDNS ipv4 and ipv6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -e # abort on nonzero exitstatus | |
set -u # abort on unbound variable | |
set -o pipefail # don't hide errors within pipes | |
TIME_START=$(date +%s%3N) | |
[ -z "$DYNDNS_LOGIN" ] && echo "missing variable DYNDNS_LOGIN" | |
[ -z "$DYNDNS_PASSWORD" ] && echo "missing variable DYNDNS_PASSWORD" | |
[ -z "$DYNDNS_HOST" ] && echo "missing variable DYNDNS_HOST" | |
[ -z "$KUMA_API_KEY" ] && echo "missing variable KUMA_API_KEY" | |
HAVE_BEEN_UPDATED=false | |
getip() { | |
CURRENT_IP4=$(curl -4 -m 5 -s -S http://ifconfig.me/ip) | |
CURRENT_IP6=$(curl -6 -m 5 -s -S http://ifconfig.me/ip) | |
OLD_IP4=$(dig A +short $DYNDNS_HOST) | |
OLD_IP6=$(dig AAAA +short $DYNDNS_HOST) | |
} | |
echo "[$(date -R)] begin dyndns check" | |
getip | |
if [ "$CURRENT_IP4" ]; then | |
if [ "$OLD_IP4" != "$CURRENT_IP4" ]; then | |
echo "[$(date -R)] Updating IPv4 from $OLD_IP4 to $CURRENT_IP4" | |
RES=$(curl -m 5 -L -s -S --location-trusted --user "$DYNDNS_LOGIN:$DYNDNS_PASSWORD" "https://dns.eu.ovhapis.com/nic/update?system=dyndns&hostname=$DYNDNS_HOST&myip=$CURRENT_IP4") | |
echo "[$(date -R)] OVH response: $RES" | |
HAVE_BEEN_UPDATED=true | |
fi | |
else | |
echo "ERROR: Unable to get current IPv4 addresse" | |
TIME_DIFF=$(($(date +%s%3N)-$TIME_START)) | |
curl -m 5 -s -S --output /dev/null "https://status.azlux.fr/api/push/$KUMA_API_KEY?status=down&msg=IPv4&ping=$TIME_DIFF" | |
exit 1 | |
fi | |
if [ "$CURRENT_IP6" ]; then | |
if [ "$OLD_IP6" != "$CURRENT_IP6" ]; then | |
echo "[$(date -R)] Updating IPv6 from $OLD_IP6 to $CURRENT_IP6" | |
RES=$(curl -m 5 -s -S -L --location-trusted --user "$DYNDNS_LOGIN:$DYNDNS_PASSWORD" "https://dns.eu.ovhapis.com/nic/update?system=dyndns&hostname=$DYNDNS_HOST&myip=$CURRENT_IP6") | |
echo "[$(date -R)] OVH response: $RES" | |
HAVE_BEEN_UPDATED=true | |
fi | |
else | |
echo "ERROR: Unable to get current IPv6 addresse" | |
TIME_DIFF=$(($(date +%s%3N)-$TIME_START)) | |
curl -m 5 -s -S --output /dev/null "https://status.azlux.fr/api/push/$KUMA_API_KEY?status=down&msg=IPv6&ping=$TIME_DIFF" | |
exit 1 | |
fi | |
TIME_DIFF=$(($(date +%s%3N)-$TIME_START)) | |
curl -m 5 -s -S --output /dev/null "https://status.azlux.fr/api/push/$KUMA_API_KEY?status=up&msg=OK&ping=$TIME_DIFF" | |
if [ "$HAVE_BEEN_UPDATED" = false ]; then | |
echo [$(date -R)] nothing to change | |
exit 0 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment