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()
This commit is contained in:
Alberto Murillo
2016-01-04 17:48:14 -06:00
parent bd3e4661cf
commit 177c860f87
+13 -2
View File
@@ -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):