From 03fe312c027cab0a99fb642993ea9312f00f079f Mon Sep 17 00:00:00 2001 From: Tine Jozelj Date: Tue, 18 Jul 2023 23:13:21 +0200 Subject: [PATCH] fix: remove cloudflare service and improve ipv4/ipv6 handling --- dyndns.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/dyndns.sh b/dyndns.sh index 9da2ba7..96d7e81 100755 --- a/dyndns.sh +++ b/dyndns.sh @@ -6,8 +6,9 @@ sleep_interval=${SLEEP_INTERVAL:-300} remove_duplicates=${REMOVE_DUPLICATES:-"false"} # Only services with ipv6 supported are listed here. +# And are not using cloudflare or similar services +# that may block requests from this script. services=( - "ifconfig.co" "ifconfig.io" ) @@ -96,19 +97,22 @@ do do echo "Trying with $service..." - ipv4="$(curl -4 -s -f $service || echo "")" - ipv6="$(curl -6 -s -f $service || echo "")" + ipv4="$(curl -4 -s -f --connect-timeout=2 $service || echo "")" + ipv6="$(curl -6 -s -f --connect-timeout=2 $service || echo "")" - test -n "$ipv4$ipv6" && break + if [[ -n "$ipv4$ipv6" ]] + then + break + else + echo "Failed to retrieve IP from $service" + fi done - echo "Found IPv4 address $ipv4" - echo "Found IPv6 address $ipv6" - if [[ -z $ipv4 ]] then echo "IPv4 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." else + echo "Found IPv4 address $ipv4" configure_record $ipv4 "A" fi @@ -116,6 +120,7 @@ do then echo "IPv6 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." else + echo "Found IPv6 address $ipv6" configure_record $ipv6 "AAAA" fi