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

🔧 handle dns server selection

This commit is contained in:
2021-09-13 13:16:27 +02:00
parent 4643331534
commit d92cdb2652

25
dynb.sh
View File

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