mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #786264 (external IP and Ubuntu's 127.0.1.1 addr)
This commit is contained in:
parent
224968f239
commit
9b52e0d4e8
@ -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})
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user