From 4e0cced632f1044a697ef9017e05539eda2e54a8 Mon Sep 17 00:00:00 2001 From: changeme Date: Thu, 25 Jun 2020 19:53:02 +0200 Subject: [PATCH 1/2] Only update ip on startup if neccessary --- src/ddns_update.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ddns_update.py b/src/ddns_update.py index 8c6c370..099ad2c 100755 --- a/src/ddns_update.py +++ b/src/ddns_update.py @@ -8,6 +8,7 @@ from os import environ from netifaces import interfaces, ifaddresses, AF_INET6 from ipaddress import ip_address from time import sleep +import socket logging.basicConfig(level=logging.INFO, format="%(asctime)-15s - %(name)s %(levelname)-8s: %(message)s") log = logging.getLogger("ddns updater") @@ -72,7 +73,9 @@ def ddns_update(host, key, ip): help="The ddns authorization key", ) def loop_ddns_update(host, key): - last_ip = None + last_ip = socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0] + log.debug(f"current registered address: {last_ip}") + while True: current_ip = get_global_ipv6() if current_ip != last_ip: @@ -84,4 +87,5 @@ def loop_ddns_update(host, key): if __name__ == "__main__": + log.info("starting...") loop_ddns_update() From 53ff70bbf31d23214872730f4bba3e313be0b2d5 Mon Sep 17 00:00:00 2001 From: changeme Date: Thu, 25 Jun 2020 19:55:23 +0200 Subject: [PATCH 2/2] Used click's own environment variable handling --- src/ddns_update.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ddns_update.py b/src/ddns_update.py index 099ad2c..9de2843 100755 --- a/src/ddns_update.py +++ b/src/ddns_update.py @@ -63,13 +63,11 @@ def ddns_update(host, key, ip): @click.option( "--host", required=True, - default=lambda: environ.get("DDNS_HOST", None), help="The dns name to update", ) @click.option( "--key", required=True, - default=lambda: environ.get("DDNS_KEY", None), help="The ddns authorization key", ) def loop_ddns_update(host, key): @@ -88,4 +86,4 @@ def loop_ddns_update(host, key): if __name__ == "__main__": log.info("starting...") - loop_ddns_update() + loop_ddns_update(auto_envvar_prefix="DDNS")