-
-
Save a-c-t-i-n-i-u-m/bc4b1ff265b277dbf195 to your computer and use it in GitHub Desktop.
#!/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 | |
# 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 |
Great script! Thank you.
I would like your thoughts on something that may help expand the utility of the script. Freenom website supports subdomains each with its own IP target. Would you please consider integrating this feature into the script?
Has this been verified to still be working?
Mine fails when it begins the #update procedure.
Would be lovely to have it working!
Hey guys, I keep using this script then fixed some issue, pls check my fork: https://gist.github.com/project-pp/a9017c231e634508cf86e6b9334683c3
Funciona muy bien. Gracias.
It works very well. Thank you.
Hi,
in October 2017 this program has stopped working. I presume that freenom has changed something.
This script did not work, so I fixed some things.
I hope this helps.
#!/bin/bash
set -u
# 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"
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/"
# get current ip address
current_ip="$(curl -s "$GET_IP_URL")"
if [ -z "$current_ip" ]; then
echo "Could not get current IP address." 1>&2
exit 1
fi
cookie_file=$(mktemp)
cleanup() {
echo "Cleanup"
rm -f "$cookie_file"
}
trap cleanup INT EXIT TERM
echo "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
echo "Login failed: empty cookie." 1>&2
exit 1
fi
if echo "$loginResult" | grep -q "/clientarea.php?incorrect=true"; then
echo "Login failed." 1>&2
exit 1
fi
echo "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
echo "Update failed." 1>&2
exit 1
fi
echo "Logout"
curl --compressed -k -b "$cookie_file" "$LOGOUT_URL" > /dev/null 2>&1
exit 0
@hwiorn thanks! It works now!
@hwiorn how to use it on synology nas or tomato router?
Thank you in advance ;)
dont work for me
@hwiorn excellent job - works great but is there a way of modifying to update the IP for a single subdomain A record without deleting all the others? I've tried adding a subdomain "name" and changing "line" to the A record line number as it appears on the page but although it correctly updates the required subdomain A record it still deletes the others.
@damianssj661 Goto control panel of your nas (default port 5000 or 5001 for https) then enable ssh or telnet. Download putty connect to your server through ssh login and download script file using wget or git clone (not sure if git is defaultly installed), open it with vim change email password and other things you need and finally add referrence to script in your crontab.
I made it check if the ip is the same and write a log file, so you change the file "config" with your parameters and execute the file "check" every 10 minutes with cron and you're done. :)
https://gist.github.com/Reiikz/4184e68892a13b97b7a8bd2e9117fc4a
Very nice!!
Hola, estoy intentando cambiar la ip publica con este script y el login va bien, pero el update no me funciona, no se si porque en el freenom_domain_id="000000000" no lo cambio, porque no se que poner , mire en freenom pero ese dato no lo veo, me podriais ayudar , muchas gracias de antemano y saludos
Hola, estoy intentando cambiar la ip publica con este script y el login va bien, pero el update no me funciona, no se si porque en el freenom_domain_id="000000000" no lo cambio, porque no se que poner , mire en freenom pero ese dato no lo veo, me podriais ayudar , muchas gracias de antemano y saludos
You have to change the zeros to the ID you get from the URL when you are on the management page for the domain. Should look something like this https://my.freenom.com/clientarea.php?managedns=example.gq&domainid=487935625
The last numbers after "domainid=" is the id you replace the zeros with.
Hola necesitas ayuda o estas contestando a mi pregunta El sáb., 26 oct. 2019 22:24, lukemagdalin notifications@github.com escribió:
…
Hola, estoy intentando cambiar la ip publica con este script y el login va bien, pero el update no me funciona, no se si porque en el freenom_domain_id="000000000" no lo cambio, porque no se que poner , mire en freenom pero ese dato no lo veo, me podriais ayudar , muchas gracias de antemano y saludos You have to change the zeros to the ID you get from the URL when you are on the management page for the domain. Should look something like this https://my.freenom.com/clientarea.php?managedns=example.gq&domainid=487935625 The last numbers after "domainid=" is the id you replace the zeros with. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/bc4b1ff265b277dbf195?email_source=notifications&email_token=ANBQE55GSVPGSSJUYSY6UYTQQSRQ7A5CNFSM4IFTZMG2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF3FWC#gistcomment-3066721, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBQE52QL477MRDGCS3UDD3QQSRQ7ANCNFSM4IFTZMGQ .
Lo que necesitas hacer como dice el compañero es cambiar los ceros de:
freenom_domain_id="000000000"
Por tu ID que la puedes obtener entrando en el panel de administración y se muestra al final como aquí (ESTO ES UN EJEMPLO):
https://my.freenom.com/clientarea.php?managedns=example.gq&domainid=487935625
Siendo la ID del ejemplo: 487935625
Y quedando el parámetro así para su correcto funcionamiento:
freenom_domain_id="487935625"
Si lo sigues sin enteder no dudes en preguntar.
Why logout each time instead of saving the cookie and avoid logging in each time?
if someone is having problems with the script, try to create a new record on the DNS MANAGEMENT page and then run the script.
WOW ITS FUCKING WORKING !
TY hwiorn AND a-c-t-i-n-i-u-m
I use this script for IP update and it works great
#!/bin/bash
set -u
# settings
# Login information of freenom.com
freenom_email="main@address"
freenom_passwd="password"
# 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="00000000000"
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/"
# get current ip address
current_ip="$(curl -s "$GET_IP_URL")"
if [ -z "$current_ip" ]; then
echo "Could not get current IP address." 1>&2
exit 1
fi
cookie_file=$(mktemp)
cleanup() {
echo "Cleanup"
rm -f "$cookie_file"
}
trap cleanup INT EXIT TERM
echo "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
echo "Login failed: empty cookie." 1>&2
exit 1
fi
if echo "$loginResult" | grep -q "/clientarea.php?incorrect=true"; then
echo "Login failed." 1>&2
exit 1
fi
echo "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
echo "Update failed." 1>&2
exit 1
fi
echo "Logout"
curl --compressed -k -b "$cookie_file" "$LOGOUT_URL" > /dev/null 2>&1
exit 0
I have one account on freenom, but 3 domains. How do I get the IP address updated on all domains? I guess this won't work
freenom_domain_name="domain1.name;domain2.name;domain3.name"
I tried it and it doesn't work
ok thank you
??
Hi, thanks for your work!
However, I tried the script and got an error in the updateResult: There was an error in the request. Please try again in a minute.
Any idea?
Freenom web works bad sometimes
for everyone else who had issues with this script (for whatever reason, the freenom website is spotty at the ebst of times), you can also use a third party service instead of adjusting the dns in the freenom website specifically with a cname record. i used duckdns.org which looked like this in freenom;
SUBDOMAIN - CNAME - 14440 - subdomain.duckdns.org
and then pointing my update service to the duckdns website. doing it this way allows you to change the freenome dns once, while you can update the actual ip address how often you want using the third party dns service.
Mmmmm... I'm testing it with my two domains on freenom.
I'm not sure that 14400 for TTL value is a good idea. I've set 300 for this value, so the update of address of *.duckdns.org will do every 5 minutes and not every 4 hours.
On freenom I had also set the main address of the domain, i.e. the one without host name and with only the domain name (so you could write "ping domain.tk" or http://domain.tk, or get an HTTPS certificate issued for the domain domani.tk).
With this change of yours, that line in the freenom config is lost, because you need to use a numeric address to configure it.
So the https certificate doesn't work either. So the https certificate for the domains doesn't work either.
Thank you, anyway.
Regards
for everyone else who had issues with this script (for whatever reason, the freenom website is spotty at the ebst of times), you can also use a third party service instead of adjusting the dns in the freenom website specifically with a cname record. i used duckdns.org which looked like this in freenom; SUBDOMAIN - CNAME - 14440 - subdomain.duckdns.org and then pointing my update service to the duckdns website. doing it this way allows you to change the freenome dns once, while you can update the actual ip address how often you want using the third party dns service.
--- EDIT ---
It works without the --compressed argument.