1
0
mirror of https://github.com/EV21/dynb.git synced 2025-12-26 16:39:32 +01:00

change: handle dns server selection

This commit is contained in:
2021-09-13 13:16:27 +02:00
parent 3ded7fc883
commit 046a728f22

25
dynb.sh
View File

@@ -41,7 +41,7 @@ _ipv4_checker=api64.ipify.org
_ipv6_checker=api64.ipify.org
## An exernal DNS check server prevents wrong info from local DNS servers/resolvers
_DNS_checkServer=1.1.1.1
_DNS_checkServer=
## if you are actively using multiple network interfaces you might want to specify this
## normally the default value is okay
@@ -161,8 +161,13 @@ function getDNSIP() {
# 2. param: IP check server address
# result to stdout
function getRemoteIP() {
if [[ -n $_DNS_checkServer ]]; then
curl --silent "$_interface_str" --user-agent "$_userAgent" \
--ipv"${1}" --dns-servers 1.1.1.1 --location "${2}"
--ipv"${1}" --dns-servers "$_DNS_checkServer" --location "${2}"
else
curl --silent "$_interface_str" --user-agent "$_userAgent" \
--ipv"${1}" --location "${2}"
fi
# shellcheck disable=2181
if [[ $? -gt 0 ]]; then
errorMessage "IPCheck (getRemoteIP ${1}) request failed"
@@ -418,7 +423,11 @@ function ipHasChanged() {
if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then
dns_ip=$(getDNSIP A)
else
dig_response=$(dig @${_DNS_checkServer} in a +short "$DYNB_DYN_DOMAIN")
if [[ -n $_DNS_checkServer ]]; then
dig_response=$(dig @"${_DNS_checkServer}" in a +short "$DYNB_DYN_DOMAIN")
else
dig_response=$(dig in a +short "$DYNB_DYN_DOMAIN")
fi
if [[ $dig_response == ";; connection timed out; no servers could be reached" ]]; then
errorMessage "DNS request failed $dig_response"
return 0
@@ -433,7 +442,11 @@ function ipHasChanged() {
if [[ $DYNB_UPDATE_METHOD == domrobot ]]; then
dns_ip=$(getDNSIP AAAA)
else
dig_response=$(dig @${_DNS_checkServer} in aaaa +short "$DYNB_DYN_DOMAIN")
if [[ -n $_DNS_checkServer ]]; then
dig_response=$(dig @"${_DNS_checkServer}" in aaaa +short "$DYNB_DYN_DOMAIN")
else
dig_response=$(dig in aaaa +short "$DYNB_DYN_DOMAIN")
fi
if [[ $dig_response == ";; connection timed out; no servers could be reached" ]]; then
errorMessage "DNS request failed $dig_response"
return 0
@@ -443,8 +456,8 @@ function ipHasChanged() {
_new_IPv6=$remote_ip
debugMessage "New IPv6: $_new_IPv6 old was: $dns_ip"
;;
* )
;;
*) ;;
esac
if [[ "$remote_ip" == "$dns_ip" ]]; then