Skip to content

Instantly share code, notes, and snippets.

@Reiikz
Forked from a-c-t-i-n-i-u-m/freenom.com.ddns.sh
Last active December 10, 2023 21:48
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reiikz/4184e68892a13b97b7a8bd2e9117fc4a to your computer and use it in GitHub Desktop.
Save Reiikz/4184e68892a13b97b7a8bd2e9117fc4a to your computer and use it in GitHub Desktop.
Dynamic DNS support shell script for freenom.com
#!/bin/bash
GET_IP_URL="https://api.ipify.org/"
UPDATE_SCRIPT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/update
LOGGER_SCRIPT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/log
source $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/config
HOST_RESULT="$(host $freenom_domain_name 80.80.80.80)"
DNS_IP=$(echo $HOST_RESULT | cut -d' ' -f 12)
CURR_IP="$(curl -s $GET_IP_URL)"
$LOGGER_SCRIPT start
$LOGGER_SCRIPT continue "Current IP: $CURR_IP :: DNS IP: $DNS_IP"
if [ $DNS_IP = $CURR_IP ]
then
$LOGGER_SCRIPT continue "No change is needed, exiting"
else
$LOGGER_SCRIPT continue "Change is needed procedeing to execute freenom update script"
$UPDATE_SCRIPT
fi
$LOGGER_SCRIPT end
#!/bin/bash
freenom_email="example@example.com"
freenom_passwd="hackme"
freenom_domain_name="example.com"
freenom_domain_id="000000000"
#!/bin/bash
FULL_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/log.log
if [ ! -e $FULL_PATH ]
then
touch $FULL_PATH
fi
case $1 in
"erase")
rm $FULL_PATH
;;
"start")
echo "Started domain address check at: $(date)" >> $FULL_PATH
;;
continue)
echo $2 >> $FULL_PATH
;;
"end")
echo "" >> $FULL_PATH
echo "" >> $FULL_PATH
echo "" >> $FULL_PATH
echo "" >> $FULL_PATH
;;
*)
echo "$1 no es una opción"
exit 1
;;
esac
#!/bin/bash
set -u
# settings
# Login information of freenom.com
# Open DNS management page in your browser.
# URL vs settings:
# https://my.freenom.com/clientarea.php?managedns={freenom_domain_name}&domainid={freenom_domain_id}
source $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/config
BASE_URL="https://my.freenom.com"
CAREA_URL="$BASE_URL/clientarea.php"
LOGIN_URL="$BASE_URL/dologin.php"
LOGOUT_URL="$BASE_URL/logout.php"
MANAGED_URL="$CAREA_URL?managedns=$freenom_domain_name&domainid=$freenom_domain_id"
GET_IP_URL="https://api.ipify.org/"
LOGGER_SCRIPT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/log
# get current ip address
current_ip="$(curl -s "$GET_IP_URL")"
if [ -z "$current_ip" ]; then
$LOGGER_SCRIPT continue "Could not get current IP address."
exit 1
fi
cookie_file=$(mktemp)
cleanup() {
$LOGGER_SCRIPT continue "Cleanup"
rm -f "$cookie_file"
}
trap cleanup INT EXIT TERM
$LOGGER_SCRIPT continue "Login"
loginResult=$(curl --compressed -k -L -c "$cookie_file" \
-F "username=$freenom_email" -F "password=$freenom_passwd" \
-e "$CAREA_URL" \
"$LOGIN_URL" 2>&1)
if [ ! -s "$cookie_file" ]; then
$LOGGER_SCRIPT continue "Login failed: empty cookie."
exit 1
fi
if echo "$loginResult" | grep -q "/clientarea.php?incorrect=true"; then
$LOGGER_SCRIPT continue "Login failed."
exit 1
fi
$LOGGER_SCRIPT continue "Update $current_ip to domain($freenom_domain_name)"
updateResult=$(curl --compressed -k -L -b "$cookie_file" \
-e "$MANAGED_URL" \
-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" \
"$MANAGED_URL" 2>&1)
if ! echo "$updateResult" | grep -q "name=\"records\[0\]\[value\]\" value=\"$current_ip\""; then
$LOGGER_SCRIPT continue "Update failed." 1>&2
exit 1
fi
$LOGGER_SCRIPT continue "Logout"
curl --compressed -k -b "$cookie_file" "$LOGOUT_URL" > /dev/null 2>&1
exit 0
@babypoodle
Copy link

Hi Reiikz,
Thanks for your feedback. and definitly will look into your suggestion see will this work for me.
Thanks once again.

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