Bug 1160094 - [moznetwork] Attempt to pick most suitable IP when multiple are associated with the hostname. r=wlach

This commit is contained in:
Dave Hunt 2015-04-30 02:52:00 +02:00
parent f32d03fb58
commit 30ab4714a6

View File

@ -113,11 +113,16 @@ def get_ip():
hostname = socket.gethostname()
try:
logger.debug('Retrieving IP for %s' % hostname)
ip = socket.gethostbyname(hostname)
ips = socket.gethostbyname_ex(hostname)[2]
except socket.gaierror: # for Mac OS X
hostname += '.local'
logger.debug('Retrieving IP for %s' % hostname)
ip = socket.gethostbyname(hostname)
ips = socket.gethostbyname_ex(hostname)[2]
if len(ips) == 1:
ip = ips[0]
else:
logger.debug('Multiple addresses found: %s' % ips)
ip = None
except socket.gaierror:
# sometimes the hostname doesn't resolve to an ip address, in which
# case this will always fail