Skip to content

Instantly share code, notes, and snippets.

@uryossa
Created June 2, 2020 02:40
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 uryossa/004957c66f32ff83eca7855ea5b8a667 to your computer and use it in GitHub Desktop.
Save uryossa/004957c66f32ff83eca7855ea5b8a667 to your computer and use it in GitHub Desktop.
Update IP Dynamic DNS dhs.org
#!/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