Files
lxtools_installer/network.py

41 lines
1.3 KiB
Python

import socket
import urllib.request
import json
class GiteaUpdate:
@staticmethod
def api_down(url, current_version=""):
"""Get latest version from Gitea API"""
try:
with urllib.request.urlopen(url, timeout=10) as response:
data = json.loads(response.read().decode())
if data and len(data) > 0:
latest_version = data[0].get("tag_name", "Unknown")
return latest_version.lstrip("v") # Remove 'v' prefix if present
return "Unknown"
except Exception as e:
print(f"API Error: {e}")
return "Unknown"
class NetworkChecker:
@staticmethod
def check_internet_connection(host="8.8.8.8", port=53, timeout=3):
"""Check if internet connection is available"""
try:
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
return True
except socket.error:
return False
@staticmethod
def check_repository_access(url="https://git.ilunix.de", timeout=5):
"""Check if repository is accessible"""
try:
urllib.request.urlopen(url, timeout=timeout)
return True
except:
return False