Merge branch 'hotfix/optional-initial-update'

master v0.0.4
changeme 2020-06-25 19:57:58 +02:00
commit 7cec842374
1 changed files with 6 additions and 4 deletions

View File

@ -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")
@ -62,17 +63,17 @@ 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):
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 +85,5 @@ def loop_ddns_update(host, key):
if __name__ == "__main__":
loop_ddns_update()
log.info("starting...")
loop_ddns_update(auto_envvar_prefix="DDNS")