Created
December 25, 2020 19:12
-
-
Save xfbs/c079aea5adf9e31c97b841a1690237e2 to your computer and use it in GitHub Desktop.
Dedyn.io Update Script
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
#!/bin/bash | |
# Script by Patrick M. Elsen <[email protected]> | |
# Updates your dedyn.io dynamic DNS, only if your IP address has changed. | |
# Licensed under MIT license. | |
# Uses openDNS IP lookup. Ideally, put this script into a cron job and run hourly. | |
set -euo pipefail | |
# dns credentials | |
dnsuser=yourdedyniousername | |
dnstoken=yourdedyniotoken | |
# where to cache ip addresses | |
ipv4_cache=/var/run/ipv4addr | |
ipv6_cache=/var/run/ipv6addr | |
# query current ip addresses | |
ipv4=$(dig @resolver3.opendns.com myip.opendns.com +short) | |
ipv6=$(dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short) | |
if [[ -f "$ipv4_cache" ]] && [[ -f "$ipv6_cache" ]]; then | |
if [[ "$(< $ipv4_cache)" == "$ipv4" ]] && [[ "$(< $ipv6_cache)" == "$ipv6" ]]; then | |
exit 0 | |
fi | |
fi | |
# update dyndns | |
response=$(curl -s --user "$dnsuser.dedyn.io:$dnstoken" "https://update.dedyn.io/?myipv4=$ipv4&myipv6=$ipv6") | |
if [[ "$response" != "good" ]]; then | |
printf "error: %s" "$response" | |
exit 1 | |
fi | |
# store addresses in cache | |
printf "%s" "$ipv4" > "$ipv4_cache" | |
printf "%s" "$ipv6" > "$ipv6_cache" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@worldwidesales @mammon69bot