commit 6ab38e11e58642d2b245df43f49cbce240f40bda Author: Vlad R Date: Sun Nov 10 15:06:21 2024 +0000 Moved to separate rep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0330071 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c50e406 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.9.13-slim-buster +WORKDIR /app +COPY . /app +RUN pip install -r requirements.txt +CMD ["python3", "-u", "update_client.py"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f890ddf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 The Developer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..c694117 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v4 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..48041ed --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +certifi==2023.11.17 +charset-normalizer==3.3.2 +idna==3.6 +python-dotenv==1.0.0 +requests==2.31.0 +urllib3==2.1.0 diff --git a/update_client.py b/update_client.py new file mode 100644 index 0000000..5075223 --- /dev/null +++ b/update_client.py @@ -0,0 +1,43 @@ +import os +import socket +from time import sleep + +import requests +from dotenv import load_dotenv + +load_dotenv() + +DDNS_WG_URL = os.environ.get("DDNS_UPDATE_WG") +DDNS_NC_URL = os.environ.get("DDNS_UPDATE_NC") +DDNS_CR_URL = os.environ.get("DDNS_UPDATE_CR") +DDNS_GT_URL = os.environ.get("DDNS_UPDATE_GT") +GT_HOST = os.environ.get("GT_HOST") +MY_IP_URL = "http://ifconfig.me" + +domains = [DDNS_NC_URL, DDNS_WG_URL, DDNS_CR_URL, DDNS_GT_URL] + +current_ip = requests.get(MY_IP_URL, timeout=15).text +registered_ip = socket.gethostbyname(GT_HOST) + +while True: + try: + current_ip = requests.get(MY_IP_URL, timeout=15).text + registered_ip = socket.gethostbyname(GT_HOST) + except Exception as e: + print(f"Error while retrieving current IP! Error:\n\n{e}") + else: + if current_ip != registered_ip: + print(f"IP change detected (was {current_ip} - now {registered_ip})! Updating DNS entries...") + for item in domains: + try: + response = requests.get(item) + print(f"Response from endpoint:\n\n{response.text}") + except Exception as e: + print(f"Error while updating DDNS entry! Error:\n\n{e}") + else: + print("DNS entry updated!") + else: + print(f"No IP change detected (currently {current_ip}).") + finally: + print("Sleeping 10 minutes...") + sleep(1200)