diff --git a/mindinsight/backend/run.py b/mindinsight/backend/run.py index b6f7aa5ce4f75110788c3bcf3c770aa096581f39..d6a600cc5fa2ee9a30d85107e7794722b652df8b 100644 --- a/mindinsight/backend/run.py +++ b/mindinsight/backend/run.py @@ -16,7 +16,6 @@ import os import re import shlex -import socket import stat import subprocess import time @@ -212,17 +211,20 @@ class GunicornLogger(Logger): def _get_all_ip_addresses(host): """Get all the accessible IP address.""" - localhost, hostname = '127.0.0.1', socket.gethostname() - _, _, ip_addresses = socket.gethostbyname_ex(hostname) - if localhost in ip_addresses: - ip_addresses.remove(localhost) - yield localhost - if host == localhost: + yield host + if host == '127.0.0.1': return - if host not in ip_addresses: - yield from ip_addresses - else: - yield host + # The format of the environment variable SSH_CONNECTION is: + # ' ' + connection = os.getenv('SSH_CONNECTION', '') + if len(connection) > 128: + # The length should be less than 128 bytes, or the variable may be corruped. + # And 128 bytes should be enough to hold two IPs and two ports. + return + connection = connection.split() + if len(connection) == 4 and connection[2] != host: + # 'connection' should hold 4 components and '' should be in index 2. + yield connection[2] def start():