Dot.tk DNS Updater

Der 'Dot.tk DNS Updater' ist ein Bashscript mit dem man die DNS Records auf dot.tk automatisiert ändern kann. In der Standardkonfiguration erledigt das Script seine Aufgabe als „Dynamic DNS“ updater.

Die Konfiguration erfolgt über die Variablen tkEmail, tkPassword und tkDomain, die DNS Records werden über die Funktion addRecord hinzugefügt.

Bitte beachte, dass es etwa eine halbe Stunde dauert, bis die Records übernommen werden

Download: tkupdater.sh

#!/bin/bash
#
# Dot.tk DNS Updater
# by Benjamin Abendroth
# licensed under GPL3

function addRecord {
	# $1 = Type [ A | CNAME | MX ]
	# $2 = Hostname 
	# $3 = IP Address
	# see http://dot.tk for farther information

	ID=$(( $ID + 42 ))
	POST+="&hosttype_$ID=$1&hostname_$ID=$2&hostcontent_$ID=$3"
}
function die {
	echo "$2"
	rm -f "$cookie" "$result"
	exit $1
}

tkEmail='mail'
tkPassword='pass'
tkDomain='xyz.tk'

currentIP=$( wget -qO- 'http://ipaddr.tk/ip' )

addRecord "A" "$tkDomain" "$currentIP"
addRecord "A" "www.$tkDomain" "$currentIP"

agent='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'
cookie=`mktemp --suffix=dotTk`
result=`mktemp --suffix=dotTk.htm`

echo -n "[+] Logging in ... "
wget -q -O /dev/null -U "$agent" --no-check-certificate \
 --save-cookies "$cookie" --keep-session-cookies \
 --post-data "fldemail=$tkEmail&fldpassword=$tkPassword" \
 "https://my.dot.tk/cgi-bin/login02.taloha"

if [ $? -eq 0 ] ; then
	echo "done"
else
	die 1 "failed"
fi

echo -n "[+] Getting domain number ... "
domainNumber=$( wget -q -O- -U "$agent" --no-check-certificate \
 --load-cookies "$cookie" --keep-session-cookies \
 "https://my.dot.tk/cgi-bin/rnt09.taloha" |grep -i -B1 "$tkDomain" \
 |grep domainnr |grep -Eo '[0-9]+' )

if [ $? -eq 0 ] && [ -n "$domainNumber" ] ; then
	echo "done. [$domainNumber]"
else
	die 2 "failed"
fi

echo -n "[+] Submitting form ... "
wget -q -O "$result" -U "$agent" --no-check-certificate \
 --keep-session-cookies --load-cookies "$cookie" --post-data \
"usage_selected=dns_tk_dns&\
usage=dns_tk_dns&\
domainnr=$domainNumber&\
flddomainnr=$domainNumber&\
action=update&\
domainname=$tkDomain\
$POST" "https://my.dot.tk/cgi-bin/rnt033.taloha"

if [ $? -eq 0 ] && grep -q "Succesfully updated" "$result" ; then
	die 0 "Succesfully updated!"
else
	die 3 "failed"
fi