Last active
October 19, 2018 23:00
-
-
Save ffflorian/87e2cca6b1c1fa45a74f41fc74a94701 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
###### 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