dyndns update: Fix for ipv6-only hosts

This commit is contained in:
Alexandre Aubin 2021-10-19 18:40:57 +02:00 committed by GitHub
parent ebed745140
commit a61d023198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -257,13 +257,17 @@ def dyndns_update(
def resolve_domain(domain, rdtype):
# FIXME make this work for IPv6-only hosts too..
ok, result = dig(dyn_host, "A")
dyn_host_ip = result[0] if ok == "ok" and len(result) else None
if not dyn_host_ip:
raise YunohostError("Failed to resolve %s" % dyn_host, raw_msg=True)
dyn_host_ipv4 = result[0] if ok == "ok" and len(result) else None
if not dyn_host_ipv4:
raise YunohostError("Failed to resolve IPv4 for %s ?" % dyn_host, raw_msg=True)
ok, result = dig(dyn_host, "AAAA")
dyn_host_ipv6 = result[0] if ok == "ok" and len(result) else None
if not dyn_host_ipv6:
raise YunohostError("Failed to resolve IPv6 for %s ?" % dyn_host, raw_msg=True)
ok, result = dig(domain, rdtype, resolvers=[dyn_host_ip])
ok, result = dig(domain, rdtype, resolvers=[dyn_host_ipv4, dyn_host_ipv6])
if ok == "ok":
return result[0] if len(result) else None
elif result[0] == "Timeout":