From 1d8021668c82b3c270b9d4669cd8c7dca27ad9d3 Mon Sep 17 00:00:00 2001 From: Junjun Zhang Date: Sun, 14 May 2017 09:53:39 -0400 Subject: [PATCH] fix getting ip address --- jtracker/jtracker.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jtracker/jtracker.py b/jtracker/jtracker.py index 899f3f2..b59fe88 100644 --- a/jtracker/jtracker.py +++ b/jtracker/jtracker.py @@ -176,9 +176,12 @@ def _init_host_id(self): def _init_host_ip(self): try: - self._host_ip = [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0] + self._host_ip = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1][0] except: - self._host_ip = '127.0.0.1' + try: + self._host_ip = [(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1] + except: + self._host_ip = '127.0.0.1' @staticmethod def _find_file(name, path):