Skip to content

Commit

Permalink
improve check domain logic
Browse files Browse the repository at this point in the history
Signed-off-by: minff <16268924+minff@users.noreply.github.com>
  • Loading branch information
minff committed Mar 11, 2024
1 parent cfe04db commit 56c8c27
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion XYZHubConnector/xyz_qgis/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
###############################################################################

import os
from typing import Iterable

from ... import __version__ as version

Expand Down Expand Up @@ -51,7 +52,24 @@ def _check_here_system(self):
from .crypter import decrypt_text

socket.setdefaulttimeout(1)
is_here_domain = decrypt_text("Vi5tWQcgFl88Wzg=") in socket.getfqdn()

def _check_host(host: str) -> bool:
is_host_reachable = False
try:
ip = socket.gethostbyname(host)
is_host_reachable = len(ip.split(".")) == 4
except:
pass
return is_host_reachable

def _check_fqdn(hosts: Iterable[str]) -> bool:
fqdn = socket.getfqdn()
return any(host in fqdn for host in hosts)

host1 = decrypt_text("Vi5tWQcgFl88Wzg=")
host2 = decrypt_text("XiRtWQcgFl88Wzg=")

is_here_domain = _check_host(host1) or _check_host(host2) or _check_fqdn([host1, host2])
return is_here_domain

def is_here_system(self):
Expand Down

0 comments on commit 56c8c27

Please sign in to comment.