Merge branch 'hotfix/optional-initial-update'
This commit is contained in:
commit
7cec842374
1 changed files with 6 additions and 4 deletions
|
@ -8,6 +8,7 @@ from os import environ
|
||||||
from netifaces import interfaces, ifaddresses, AF_INET6
|
from netifaces import interfaces, ifaddresses, AF_INET6
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import socket
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)-15s - %(name)s %(levelname)-8s: %(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)-15s - %(name)s %(levelname)-8s: %(message)s")
|
||||||
log = logging.getLogger("ddns updater")
|
log = logging.getLogger("ddns updater")
|
||||||
|
@ -62,17 +63,17 @@ def ddns_update(host, key, ip):
|
||||||
@click.option(
|
@click.option(
|
||||||
"--host",
|
"--host",
|
||||||
required=True,
|
required=True,
|
||||||
default=lambda: environ.get("DDNS_HOST", None),
|
|
||||||
help="The dns name to update",
|
help="The dns name to update",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--key",
|
"--key",
|
||||||
required=True,
|
required=True,
|
||||||
default=lambda: environ.get("DDNS_KEY", None),
|
|
||||||
help="The ddns authorization key",
|
help="The ddns authorization key",
|
||||||
)
|
)
|
||||||
def loop_ddns_update(host, 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:
|
while True:
|
||||||
current_ip = get_global_ipv6()
|
current_ip = get_global_ipv6()
|
||||||
if current_ip != last_ip:
|
if current_ip != last_ip:
|
||||||
|
@ -84,4 +85,5 @@ def loop_ddns_update(host, key):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
loop_ddns_update()
|
log.info("starting...")
|
||||||
|
loop_ddns_update(auto_envvar_prefix="DDNS")
|
||||||
|
|
Loading…
Reference in a new issue