Skip to content

Instantly share code, notes, and snippets.

@kampro
Forked from a-c-t-i-n-i-u-m/freenom.com.ddns.sh
Last active May 14, 2016 03:00
Show Gist options
  • Save kampro/f7fbad000d4f83ecaca3824979217d5a to your computer and use it in GitHub Desktop.
Save kampro/f7fbad000d4f83ecaca3824979217d5a to your computer and use it in GitHub Desktop.
Dynamic DNS support shell script for freenom.com
#!/bin/bash
# settings
# Login information of freenom.com
freenom_email="main@address"
freenom_passwd="pswd"
# Open DNS management page in your browser.
# URL vs settings:
# https://my.freenom.com/clientarea.php?managedns={freenom_domain_name}&domainid={freenom_domain_id}
freenom_domain_name="domain.name"
freenom_domain_id="000000000"
# main
# get current ip address
current_ip="$(curl -s "https://api.ipify.org/")"
if [ "${current_ip}" == "" ]; then
echo "Could not get current IP address." 1>&2
exit 1
fi
last_ip=$(<"current-ip.txt")
if [ "${current_ip}" == "${last-ip}" ]
then
exit 0
fi
echo "${current_ip}">"current-ip.txt"
# login
cookie_file=$(mktemp)
loginResult=$(curl --compressed -k -L -c "${cookie_file}" \
-F "username=${freenom_email}" -F "password=${freenom_passwd}" \
"https://my.freenom.com/dologin.php" 2>&1)
if [ "$(echo -e "${loginResult}" | grep "/clientarea.php?incorrect=true")" != "" ]; then
echo "Login failed." 1>&2
exit 1
fi
# update
updateResult=$(curl --compressed -k -L -b "${cookie_file}" \
-F "dnsaction=modify" -F "records[0][line]=" -F "records[0][type]=A" -F "records[0][name]=" -F "records[0][ttl]=14440" -F "records[0][value]=${current_ip}" \
"https://my.freenom.com/clientarea.php?managedns=${freenom_domain_name}&domainid=${freenom_domain_id}" 2>&1)
if [ "$(echo -e "$updateResult" | grep "<li class=\"dnssuccess\">")" == "" ]; then
echo "Update failed." 1>&2
exit 1
fi
# logout
curl --compressed -k -b "${cookie_file}" "https://my.freenom.com/logout.php" > /dev/null 2>&1
# clean up
rm -f ${cookie_file}
exit 0
@kampro
Copy link
Author

kampro commented Apr 3, 2016

Added storing IP in file and checking if current IP is different to previous one, if they are the same script does nothing.

@ma-santamaria
Copy link

There is a typo in line 24; "last-ip" should be "last_ip"

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment