Created
October 6, 2012 12:17
-
-
Save lo48576/3844770 to your computer and use it in GitHub Desktop.
update ddns of ddo.jp
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/sh | |
CURRENT_IP_FILE=/opt/nu11p0_6477/ddns/CRT_IP.dat | |
# seconds | |
# 7 days = 604800 seconds | |
FORCE_UPDATE=604800 | |
# set your username and password | |
USER="user" | |
PASSWORD="password" | |
get_global_ip_with_ieserver_net() { | |
wget -q -O - ipcheck.ieserver.net | |
} | |
get_global_ip_with_mycurse_net() { | |
wget -q -O - ipcheck.mycurse.net | |
} | |
get_global_ip_with_ddo_jp() { | |
wget -q -O - http://info.ddo.jp/remote_addr.php | awk -F':' '/^REMOTE_ADDR:/{print $2}' | |
} | |
get_global_ip() { | |
get_global_ip_with_ieserver_net | |
} | |
# seconds | |
# 7 days = 604800 seconds | |
LOG=/var/log/ddns.log | |
CURRENT_TIME="`date +%s`" | |
NEW_IP="`get_global_ip`" | |
update() { | |
# for ddo.jp | |
wget -q -O - "http://free.ddo.jp/dnsupdate.php?dn=${USER}&pw=${PASSWORD}" >/dev/null | |
echo "${CURRENT_TIME} ${NEW_IP}" > $CURRENT_IP_FILE | |
} | |
main() { | |
CURRENT_IP_DATA="`cat $CURRENT_IP_FILE`" | |
LAST_CHANGED="`echo ${CURRENT_IP_DATA} | awk '{print $1}'`" | |
CURRENT_IP="`echo ${CURRENT_IP_DATA} | awk '{print $2}'`" | |
if [ $(( $LAST_CHANGED + $FORCE_UPDATE )) -lt $CURRENT_TIME ] ; then | |
update | |
echo "Updated. ($FORCE_UPDATE seconds has past.)" >> $LOG | |
elif [ "$NEW_IP" != "$CURRENT_IP" ] ; then | |
update | |
echo "Updated. (IP address changed: ${CURRENT_IP} -> ${NEW_IP})" >> $LOG | |
fi | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment