mirror of https://github.com/nicolargo/glances
Change the function to get the IPv4 active address to use in the autodiscover mode (issue #452)
parent
b743d6ace0
commit
03743421f0
|
@ -177,11 +177,11 @@ class GlancesAutoDiscoverClient(object):
|
||||||
|
|
||||||
def __init__(self, hostname, args=None):
|
def __init__(self, hostname, args=None):
|
||||||
if netifaces_tag:
|
if netifaces_tag:
|
||||||
try:
|
# -B @ overwrite the dynamic IPv4 choice
|
||||||
zeroconf_bind_address = netifaces.ifaddresses(
|
if args.bind_address != '0.0.0.0':
|
||||||
netifaces.interfaces()[1])[netifaces.AF_INET][0]['addr']
|
|
||||||
except:
|
|
||||||
zeroconf_bind_address = args.bind_address
|
zeroconf_bind_address = args.bind_address
|
||||||
|
else:
|
||||||
|
zeroconf_bind_address = self.find_active_ip_address()
|
||||||
print("Announce the Glances server on the local area network (using %s IP address)" %
|
print("Announce the Glances server on the local area network (using %s IP address)" %
|
||||||
zeroconf_bind_address)
|
zeroconf_bind_address)
|
||||||
|
|
||||||
|
@ -211,6 +211,16 @@ class GlancesAutoDiscoverClient(object):
|
||||||
logger.error(
|
logger.error(
|
||||||
"Can not announce Glances server on the network (Netifaces lib is not installed)")
|
"Can not announce Glances server on the network (Netifaces lib is not installed)")
|
||||||
|
|
||||||
|
def find_active_ip_address(self):
|
||||||
|
"""Try to find the active IP addresses"""
|
||||||
|
try:
|
||||||
|
# Interface of the default gatewau
|
||||||
|
gateway_itf = netifaces.gateways()['default'][netifaces.AF_INET][1]
|
||||||
|
# IP address for the interface
|
||||||
|
return netifaces.ifaddresses(gateway_itf)[netifaces.AF_INET][0]['addr']
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if zeroconf_tag:
|
if zeroconf_tag:
|
||||||
self.zeroconf.unregister_service(self.info)
|
self.zeroconf.unregister_service(self.info)
|
||||||
|
|
Loading…
Reference in New Issue