We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e9a2916 commit 7a845cdCopy full SHA for 7a845cd
cryosparc/platform.py
@@ -4,7 +4,24 @@
4
from pathlib import Path
5
from typing import Callable
6
7
-__all__ = ("user_config_path",)
+__all__ = ("is_localhost", "user_config_path")
8
+
9
10
+def is_localhost(hostname: str) -> bool:
11
+ """
12
+ Check if a hostname refers to the current host.
13
14
+ import socket
15
16
+ if hostname == "localhost" or hostname.startswith("127.") or hostname == "::1":
17
+ return True
18
+ if hostname == socket.gethostname().replace(" ", "") or hostname == socket.getfqdn().replace(" ", ""):
19
20
+ try:
21
+ ip = socket.gethostbyname(hostname).strip()
22
+ return ip.startswith("127.") or ip == "::1"
23
+ except Exception:
24
+ return False
25
26
27
def user_config_path() -> Path:
0 commit comments