Fix #786264 (external IP and Ubuntu's 127.0.1.1 addr)

This commit is contained in:
Kovid Goyal 2011-05-21 12:49:17 -06:00
parent 224968f239
commit 9b52e0d4e8
2 changed files with 5 additions and 4 deletions

View File

@ -218,7 +218,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
cherrypy.engine.start()
except:
ip = get_external_ip()
if not ip or ip == '127.0.0.1':
if not ip or ip.startswith('127.'):
raise
cherrypy.log('Trying to bind to single interface: '+ip)
cherrypy.config.update({'server.socket_host' : ip})

View File

@ -13,16 +13,17 @@ def _get_external_ip():
ipaddr = socket.gethostbyname(socket.gethostname())
except:
ipaddr = '127.0.0.1'
if ipaddr == '127.0.0.1':
if ipaddr.startswith('127.'):
for addr in ('192.0.2.0', '198.51.100.0', 'google.com'):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((addr, 0))
ipaddr = s.getsockname()[0]
if ipaddr != '127.0.0.1':
return ipaddr
if not ipaddr.startswith('127.'):
break
except:
time.sleep(0.3)
#print 'ipaddr: %s' % ipaddr
return ipaddr
_ext_ip = None