dennybaa
7/2/2015 - 11:19 PM

Update dyndns freedns http://freedns.afraid.org/

Update dyndns freedns http://freedns.afraid.org/

#!/bin/sh
#FreeDNS updater script

(which wget > /dev/null) || { echo "wget not found"; exit 1; }
(which nslookup > /dev/null) || { echo "nslookup not found"; exit 1; }

# FREEDNS_APIKEY (loginid|password -> SHA1)
DYNLIST=$(wget -qO- http://freedns.afraid.org/api/?action=getdyndns&sha=${FREEDNS_APIKEY})
NAME="$1"

DYNLIST=$(wget -qO- "http://freedns.afraid.org/api/?action=getdyndns&sha=${FREEDNS_APIKEY}")

for record in $DYNLIST; do
  dns_name=$(echo $record | cut -f1 -d\|)

  if [ "$NAME" = "$dns_name" ]; then
    record_addr=$(echo $record | cut -f2 -d\|)
    # take extarnal ip, kinda ifconfig.me but faster
    host_addr=$(wget -q -O - http://checkip.dyndns.org | sed 's/[^0-9.]//g')

    if [ "$host_addr" != "$record_addr" ]; then
      update_link=$(echo $record | cut -f3 -d\|)
      wget -qO- "$update_link"
    fi
  fi

done