Created
January 13, 2024 16:07
-
-
Save renne/6c4379ff73b1a012ab37810cac5dfef4 to your computer and use it in GitHub Desktop.
Dyndns2 Bash 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 | |
if [ -r "${0%.sh}.conf" ]; then { | |
. "${0%.sh}.conf" | |
} else { | |
echo -e "\n\tAdd the variables HOSTNAME, USERNAME and PASSWORD to the file ${0%.sh}.conf, adjust the update URL and run this script once a minute!\n" | |
}; fi | |
DIG="`which dig` +short" | |
NS0_NAME=`${DIG} SOA ${HOSTNAME} | sed -e 's/\. .*//'` | |
DNS_IPv4=`${DIG} A ${HOSTNAME} @${NS0_NAME}` | |
DNS_IPv6=`${DIG} AAAA ${HOSTNAME} @${NS0_NAME}` | |
NET_IPv4=`${DIG} TXT o-o.myaddr.l.google.com @ns1.google.com -4` | |
NET_IPv6=`${DIG} TXT o-o.myaddr.l.google.com @ns1.google.com -6` | |
NET_IPv4="${NET_IPv4//\"/}" | |
NET_IPv6="${NET_IPv6//\"/}" | |
echo -e "NS0 NAME: ${NS0_NAME}\nDNS IPv4: ${DNS_IPv4}\nNET IPv4: ${NET_IPv4}\nDNS IPv6: ${DNS_IPv6}\nNET IPv6: ${NET_IPv6}" | |
[ -z "${NET_IPv4}" ] && exit | |
[ -z "${NET_IPv6}" ] && exit | |
[ "${DNS_IPv4}" = "${NET_IPv4}" ] && [ "${DNS_IPv6}" = "${NET_IPv6}" ] && exit | |
/usr/bin/curl --silent --user "${USERNAME}:${PASSWORD}" "https://dyndns.inwx.com/nic/update?myip=${NET_IPv4}&myipv6=${NET_IPv6}" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment