Skip to content

Instantly share code, notes, and snippets.

@ffflorian
Last active October 19, 2018 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffflorian/87e2cca6b1c1fa45a74f41fc74a94701 to your computer and use it in GitHub Desktop.
Save ffflorian/87e2cca6b1c1fa45a74f41fc74a94701 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
###### Configuration ################################
USER=""
PASSWORD=""
IP_PROVIDER="ip4.ident.me"
#####################################################
INWX_API="https://dyndns.inwx.com/nic/update"
_CHECK_RESULT() {
RESULT="${1}"
if [ "${RESULT}" == "good" ] || [ "${RESULT}" == "nochg" ]; then
echo "Done. Result was \"${RESULT}\"."
else
echo "Error: DynDNS update failed. Result was \"${RESULT}\"."
exit 1
fi
}
_RUN_CURL() {
MY_IP="$(curl -sL "${IP_PROVIDER}")"
IP_STATUS="$?"
if [ -z "${MY_IP}" ] || [ "${IP_STATUS}" != "0" ]; then
echo "Error: could not get IP address."
exit 1
fi
RESULT="$(curl -sL -u "${USER}:${PASSWORD}" "${INWX_API}?myip=${MY_IP}")"
_CHECK_RESULT "${RESULT}"
}
_RUN_WGET() {
MY_IP="$(wget -O- -q "${IP_PROVIDER}")"
IP_STATUS="$?"
if [ -z "${MY_IP}" ] || [ "${IP_STATUS}" != "0" ]; then
echo "Error: could not get IP address."
exit 1
fi
RESULT="$(wget -O- -q --http-user "${USER}" --http-password "${PASSWORD}" "${INWX_API}?myip=${MY_IP}")"
_CHECK_RESULT "${RESULT}"
}
if command -v curl > /dev/null; then
_RUN_CURL
else
_RUN_WGET
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment