IPDIR="$(cd "$(dirname "$0")";pwd)/IP"# store last ip in script folder APIKEY="your_api_key" DOMAIN="your_domain"# world.com HOST="your_host"# hello IP="$(ifconfig | sed -n "s/.*:\(.*\)P-t-P.*/\1/p")"# get public ip by ifconfig API='https://www.namesilo.com/api'
if [ -f $IPDIR ]; then LASTIP="$(cat $IPDIR)" else LASTIP="0.0.0.0" fi
if [[ "$IP" != "$LASTIP" ]]; then echo$IP > $IPDIR
if [ -z "$HOST" ]; then FULLDOMAIN=$DOMAIN else FULLDOMAIN="\\$HOST.$DOMAIN" fi
# Fetch DNS record ID RESPONSE="$(curl -s --insecure "$API/dnsListRecords?version=1&type=xml&key=$APIKEY&domain=$DOMAIN")" RECORD_ID="$(echo $RESPONSE | sed -n "s/^.*<record_id>\(.*\)<\/record_id>.*<host>$FULLDOMAIN<\/host>.*$/\1/p")"
# Update DNS record in Namesilo RESPONSE="$(curl -s --insecure "$API/dnsUpdateRecord?version=1&type=xml&key=$APIKEY&domain=$DOMAIN&rrid=$RECORD_ID&rrhost=$HOST&rrvalue=$IP&rrttl=3600")"
# Check whether the update was successful echo$RESPONSE | grep -E "<code>(280|300)</code>" &>/dev/null
if [ $? -eq 0 ]; then echo'IP Update Success!' else echo'IP Update Failed!' fi
else echo'IP Not Need Update!' fi
定时更新
1
*/5 * * * * /your_path_to_script/your_script_name.sh # every five minutes