mirror of
https://github.com/clearlinux/clearstack.git
synced 2026-11-22 05:42:41 +00:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user