@@ -17,10 +17,9 @@ def get_hostname() -> str:
17
17
18
18
>>> result = get_hostname()
19
19
>>> assert len(result) > 1
20
-
21
20
"""
22
21
23
- if get_is_platform_windows_wine (): # for wine get hostname not via IP Adress - would give name of the host
22
+ if get_is_platform_windows_wine (): # for wine get hostname not via IP Adress - that would give name of the linux host
24
23
# noinspection PyBroadException
25
24
try :
26
25
result_wine_reg = lib_registry .Registry ().get_value (key = r'HKLM\System\CurrentControlSet\Control\ComputerName' , value_name = 'ComputerName' )
@@ -34,7 +33,7 @@ def get_hostname() -> str:
34
33
_hostname = result_wine_env
35
34
36
35
elif get_is_platform_windows ():
37
- _hostname = socket . getfqdn ()
36
+ _hostname = _get_fqdn_by_hostname ()
38
37
else :
39
38
# this one failed on the first call sometimes - use now getfqdn() supports both IPv4 and IPv6. - and sometimes give WRONG HOSTNAME
40
39
# _hostname = socket.gethostbyaddr(socket.gethostname())[0]
@@ -49,6 +48,22 @@ def get_hostname() -> str:
49
48
return str (_hostname )
50
49
51
50
51
+ def _get_fqdn_by_hostname () -> str :
52
+ """
53
+ Returns fqdn by hostname
54
+ if You use just socket.getfqdn(), it will return 'dslauncher.3ds.com' if Solid Works 3DExperience is installed.
55
+ this is because they tinker with the loopback address
56
+ therefore we get hostname --> ip adress --> fqdn
57
+
58
+ >>> assert _get_fqdn_by_hostname()
59
+
60
+ """
61
+ _hostname_short = socket .gethostname ()
62
+ _ip_address = socket .gethostbyname (_hostname_short )
63
+ _fqdn = socket .getfqdn (name = _ip_address )
64
+ return _fqdn
65
+
66
+
52
67
def get_hostname_short () -> str :
53
68
"""
54
69
Returns hostname lowercase without domain part
0 commit comments