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()
|
cherrypy.engine.start()
|
||||||
except:
|
except:
|
||||||
ip = get_external_ip()
|
ip = get_external_ip()
|
||||||
if not ip or ip == '127.0.0.1':
|
if not ip or ip.startswith('127.'):
|
||||||
raise
|
raise
|
||||||
cherrypy.log('Trying to bind to single interface: '+ip)
|
cherrypy.log('Trying to bind to single interface: '+ip)
|
||||||
cherrypy.config.update({'server.socket_host' : ip})
|
cherrypy.config.update({'server.socket_host' : ip})
|
||||||
|
@ -13,16 +13,17 @@ def _get_external_ip():
|
|||||||
ipaddr = socket.gethostbyname(socket.gethostname())
|
ipaddr = socket.gethostbyname(socket.gethostname())
|
||||||
except:
|
except:
|
||||||
ipaddr = '127.0.0.1'
|
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'):
|
for addr in ('192.0.2.0', '198.51.100.0', 'google.com'):
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
s.connect((addr, 0))
|
s.connect((addr, 0))
|
||||||
ipaddr = s.getsockname()[0]
|
ipaddr = s.getsockname()[0]
|
||||||
if ipaddr != '127.0.0.1':
|
if not ipaddr.startswith('127.'):
|
||||||
return ipaddr
|
break
|
||||||
except:
|
except:
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
|
#print 'ipaddr: %s' % ipaddr
|
||||||
return ipaddr
|
return ipaddr
|
||||||
|
|
||||||
_ext_ip = None
|
_ext_ip = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user