Moved to separate rep

This commit is contained in:
Vlad R 2024-11-10 15:06:21 +00:00
commit 6ab38e11e5
6 changed files with 78 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
venv
.env

5
Dockerfile Normal file
View File

@ -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"]

21
LICENSE Normal file
View File

@ -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.

1
VERSION Normal file
View File

@ -0,0 +1 @@
v4

6
requirements.txt Normal file
View File

@ -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

43
update_client.py Normal file
View File

@ -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)