sh freenom.com的动态DNS支持shell脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh freenom.com的动态DNS支持shell脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#
# settings
#
# login data
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 url
current_ip="$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com 2>/dev/null | tr -d '"')"
log_file="/tmp/$(basename $0)"
if [ "$current_ip" == "" ]; then
echo "[$(date)] Couldn't get current global ip address." >> ${log_file}.log
exit 1
fi
if [ "$(cat ${log_file}.ip 2>/dev/null)" == "$current_ip" ]; then
exit 0
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 "Location: /clientarea.php?incorrect=true")" != "" ]; then
echo "[$(date)] Login failed." >> ${log_file}.log
rm -f $cookie_file
exit 1
fi
# if record does not exists, add new record, else update the first record; records[0]
dnsManagementURL="https://my.freenom.com/clientarea.php?managedns=$freenom_domain_name&domainid=$freenom_domain_id"
if [ "$(curl --compressed -k -L -b "$cookie_file" "$dnsManagementURL" 2>&1 | grep -F "records[0]")" == "" ]; then
recordKey="addrecord[0]"
dnsAction="add"
else
recordKey="records[0]"
dnsAction="modify"
fi
# request add/update DNS record
updateResult=$(curl --compressed -k -L -b "$cookie_file" \
-F "dnsaction=$dnsAction" \
-F "$recordKey[line]=" \
-F "$recordKey[type]=A" \
-F "$recordKey[name]=" \
-F "$recordKey[ttl]=14440" \
-F "$recordKey[value]=$current_ip" \
"$dnsManagementURL" 2>&1)
# logout
curl --compressed -k -b "$cookie_file" "https://my.freenom.com/logout.php" > /dev/null 2>&1
# clean up
rm -f $cookie_file
if [ "$(echo -e "$updateResult" | grep "$current_ip")" == "" ]; then
echo "[$(date)] Update failed." >> ${log_file}.log
echo -e "$updateResult" > ${log_file}.errorUpdateResult.log
exit 1
else
# save ip address
echo -n "$current_ip" > ${log_file}.ip
exit 0
fi
以上是关于sh freenom.com的动态DNS支持shell脚本的主要内容,如果未能解决你的问题,请参考以下文章
Freenom.com 和 AWS Amplify:亚马逊要求我“配置根域”(@ANAME abc-whatever-xyz.cloudfront.net)-> Freenom:不允许使用通配符
自建动态DNS(DDNS)服务器
linux_shell 编程学习-初识she'll
CentOS 7配置Let’s Encrypt支持免费泛域名证书
本地局域网内或路由器后面的动态IP更新(到DNS服务,如zoneedit或dyndns)
基于 DNS 动态发现方式部署 Etcd 集群