From 41e47d225df40a5edabb5a131df5dc85afc888bc Mon Sep 17 00:00:00 2001 From: Li Hongzhang Date: Fri, 14 Aug 2020 19:41:03 +0800 Subject: [PATCH] optional print ssh server ip --- mindinsight/backend/run.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mindinsight/backend/run.py b/mindinsight/backend/run.py index b6f7aa5c..d6a600cc 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():