Compare commits

..

No commits in common. "master" and "v0.0.2" have entirely different histories.

3 changed files with 7 additions and 30 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
__pycache__/

View File

@ -8,7 +8,6 @@ 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")
@ -34,7 +33,7 @@ def response_successful(response_text):
def ddns_update(host, key, ip): def ddns_update(host, key, ip):
url = f"https://dyndns.strato.com/nic/update?hostname={host}&myip={ip}" url = f"https://dyndns.strato_.com/nic/update?hostname={host}&myip={ip}"
try: try:
response = requests.get(url, auth=(host, key), timeout=3) response = requests.get(url, auth=(host, key), timeout=3)
@ -46,7 +45,7 @@ def ddns_update(host, key, ip):
response.raise_for_status() response.raise_for_status()
if not response_successful(response.text): if not response_successful(response.text):
raise RequestException(f"update to {ip} failed") raise RequestException("update failed")
except RequestException as error: except RequestException as error:
log.error(response.text.strip()) log.error(response.text.strip())
@ -54,7 +53,7 @@ def ddns_update(host, key, ip):
return False return False
log.debug(response.text.strip()) log.debug(response.text.strip())
log.info(f"update to {ip} successful") log.info("update successful")
return True return True
@ -63,17 +62,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 = ip_address(socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0]) last_ip = None
log.info(f"currently 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:
@ -85,5 +84,4 @@ def loop_ddns_update(host, key):
if __name__ == "__main__": if __name__ == "__main__":
log.info("starting...") loop_ddns_update()
loop_ddns_update(auto_envvar_prefix="DDNS")

View File

@ -1,20 +0,0 @@
import unittest
from .ddns_update import response_successful
class TestDdnsUpdate(unittest.TestCase):
def test_response_successful(self):
self.assertTrue(response_successful("good"))
self.assertTrue(response_successful("good 1.2.3.4"))
self.assertTrue(response_successful("good abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd"))
self.assertTrue(response_successful("nochg"))
self.assertTrue(response_successful("nochg 1.2.3.4"))
self.assertTrue(response_successful("nochg abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd"))
self.assertFalse(response_successful("notfqdn"))
self.assertFalse(response_successful("nohost"))
self.assertFalse(response_successful("numhost"))
self.assertFalse(response_successful("abuse"))
self.assertFalse(response_successful("badagent"))
self.assertFalse(response_successful("dnserr"))
self.assertFalse(response_successful("911"))