From 177c860f87300131f8dcbe165876b97ae6a4f5ee Mon Sep 17 00:00:00 2001 From: Alberto Murillo Date: Mon, 4 Jan 2016 17:35:22 -0600 Subject: [PATCH] Improve is_localhost function Clearstack was treating ips other than the one with default gw as non local ips. - add get_ips() function to return all addresses on the system - make is_localhost check if the ip is in the output of get_ips() --- clearstack/common/util.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/clearstack/common/util.py b/clearstack/common/util.py index 8f81fbe..98b6194 100644 --- a/clearstack/common/util.py +++ b/clearstack/common/util.py @@ -174,14 +174,25 @@ def get_net_interface(): return (netifaces.gateways())['default'][netifaces.AF_INET][1] +def get_ips(): + ips = [] + for iface in netifaces.interfaces(): + try: + for addr in netifaces.ifaddresses(iface)[netifaces.AF_INET]: + ips.append(addr['addr']) + except: + pass + return ips + + def get_ip(): interface = get_net_interface() return netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'] def is_localhost(host): - return host == "localhost" or host == "127.0.0.1" or \ - host == socket.gethostname() or host == get_ip() + return (host == "localhost" or host == socket.gethostname() + or host in get_ips()) def has_localhost(hosts):