Skip to content

Commit

Permalink
Bug 1160094 - [moznetwork] Attempt to pick most suitable IP when mult…
Browse files Browse the repository at this point in the history
…iple are associated with the hostname. r=wlach
  • Loading branch information
davehunt committed Apr 30, 2015
1 parent ba3cfb6 commit 23ee6ca
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions testing/mozbase/moznetwork/moznetwork/moznetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23ee6ca

Please sign in to comment.