Skip to content

Instantly share code, notes, and snippets.

@Porygon31
Created February 18, 2025 12:34
Show Gist options
  • Save Porygon31/ad2076456a4e40437b265fb40b76ef06 to your computer and use it in GitHub Desktop.
Save Porygon31/ad2076456a4e40437b265fb40b76ef06 to your computer and use it in GitHub Desktop.
A lightweight Python script that checks AdGuard DNS updates every 30 minutes, logs results, and runs in the system tray. Users can view the latest response and manually trigger a scan via a pop-up dialog.
import requests
import time
import os
import pystray
from pystray import Icon, MenuItem, Menu
from PIL import Image
import threading
import tkinter as tk
from tkinter import messagebox
URL = "https://linkip.adguard-dns.com/linkip/LOOK_ON_YOUR_PROFILE_TO_GET_YOUR_OWN_URL"
LOG_FILE = "AdGuardDNS_Log.txt"
ICON_FILE = "AdGuard_DNS_Updater.ico"
last_response = "Pas encore de réponse"
last_request_time = "Jamais"
# Vérifier si le fichier de log existe, sinon le créer
if not os.path.exists(LOG_FILE):
with open(LOG_FILE, "w") as log:
log.write("Journal de connexion AdGuard DNS Updater\n")
def fetch_data():
global last_response, last_request_time
while True:
last_request_time = time.strftime('%Y-%m-%d %H:%M:%S')
try:
response = requests.get(URL)
response.raise_for_status()
last_response = response.text
with open(LOG_FILE, "a") as log:
log.write(f"{last_request_time} - Succès: {last_response}\n")
except requests.RequestException:
last_response = "Erreur de connexion"
with open(LOG_FILE, "a") as log:
log.write(f"{last_request_time} - Erreur de connexion\n")
time.sleep(1800) # 30 minutes
def show_response():
root = tk.Tk()
root.withdraw()
messagebox.showinfo("Réponse du site", f"{last_response}\n\nDernière requête à: {last_request_time}")
def quit_script(icon, item):
icon.stop()
os._exit(0)
def setup_tray():
icon_image = Image.open(ICON_FILE)
menu = Menu(MenuItem("Afficher la réponse", lambda icon, item: show_response()),
MenuItem("Quitter", quit_script))
tray_icon = Icon("AdGuard DNS Updater", icon_image, menu=menu)
tray_icon.run()
if __name__ == "__main__":
threading.Thread(target=fetch_data, daemon=True).start()
setup_tray()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment