Created
June 2, 2020 02:40
-
-
Save uryossa/004957c66f32ff83eca7855ea5b8a667 to your computer and use it in GitHub Desktop.
Update IP Dynamic DNS dhs.org
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
#!/bin/bash | |
RETVAL=0 | |
USER=username | |
PASSWORD=password | |
HOSTNAME=hostname | |
DOMAIN=dyn.dhs.org | |
CHECKIPURL=http://checkip.dyndns.org:8245/ | |
WANIPNEWCACHE=/var/tmp/wanip-cache-new | |
WANIPOLDCACHE=/var/tmp/wanip-cache-old | |
#DEBUG 1:Enable 0:Disable | |
DEBUG=0 | |
WANIP=$(curl -s -L "${CHECKIPURL}" | grep "Current IP Address:" | grep -o -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") | |
if [ -z "${WANIP}" ]; then | |
echo "Cannot get WANIP" | |
exit 1 | |
fi | |
echo $WANIP >${WANIPNEWCACHE} | |
if [ -f "${WANIPOLDCACHE}" ]; then | |
OLDIP=$(head -n1 "${WANIPOLDCACHE}") | |
else | |
echo "This is First running." | |
fi | |
if [ "${OLDIP}" = "${WANIP}" ]; then | |
[ "${DEBUG}" = "1" ] && echo "no change ip:${WANIP}" | |
[ "${DEBUG}" = "1" ] && echo "do not update ddns:${HOSTNAME}.${DOMAIN}" | |
exit 0 | |
fi | |
curl -k -X POST "https://${USER}:${PASSWORD}@members.dhs.org/nic/hosts" -d "domain=${DOMAIN}&hostname=${HOSTNAME}&hostscmd=edit&hostscmdstage=2&type=4&updatetype=Online&ip=${WANIP}&submit=Update" | |
if [ "$?" -ne "0" ]; then | |
RETVAL=1 | |
else | |
echo "change ip:${WANIP}" | |
echo "updated ddns:${HOSTNAME}.${DOMAIN}" | |
fi | |
cp -f "${WANIPNEWCACHE}" "${WANIPOLDCACHE}" | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment