|
@ -525,30 +525,24 @@ def all_localhosts(): |
|
|
return ips |
|
|
return ips |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ipv_localhost(v): |
|
|
def check_resolve(host): |
|
|
""" Return True if localhost resolves to some IPV4 ('4') or IPV6 ('6') address |
|
|
""" Return True if 'host' resolves |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
info = socket.getaddrinfo('localhost', None) |
|
|
info = socket.getaddrinfo(host, None) |
|
|
except: |
|
|
except: |
|
|
# localhost does not resolve |
|
|
# Does not resolve |
|
|
return False |
|
|
return False |
|
|
for item in info: |
|
|
return True |
|
|
item = item[4][0] |
|
|
|
|
|
if v == '4' and ':' not in item: |
|
|
|
|
|
return True |
|
|
|
|
|
elif v == '6' and ':' in item: |
|
|
|
|
|
return True |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
|
#------------------------------------------------------------------------------ |
|
|
def get_webhost(cherryhost, cherryport, https_port): |
|
|
def get_webhost(cherryhost, cherryport, https_port): |
|
|
""" Determine the webhost address and port, |
|
|
""" Determine the webhost address and port, |
|
|
return (host, port, browserhost) |
|
|
return (host, port, browserhost) |
|
|
""" |
|
|
""" |
|
|
if cherryhost == '0.0.0.0' and not ipv_localhost('4'): |
|
|
if cherryhost == '0.0.0.0' and not check_resolve('127.0.0.1'): |
|
|
cherryhost = '' |
|
|
cherryhost = '' |
|
|
elif cherryhost == '::' and not ipv_localhost('6'): |
|
|
elif cherryhost == '::' and not check_resolve('::1'): |
|
|
cherryhost = '' |
|
|
cherryhost = '' |
|
|
|
|
|
|
|
|
if cherryhost is None: |
|
|
if cherryhost is None: |
|
@ -563,14 +557,18 @@ def get_webhost(cherryhost, cherryport, https_port): |
|
|
try: |
|
|
try: |
|
|
info = socket.getaddrinfo(socket.gethostname(), None) |
|
|
info = socket.getaddrinfo(socket.gethostname(), None) |
|
|
except: |
|
|
except: |
|
|
# Hostname does not resolve, use 0.0.0.0 |
|
|
# Hostname does not resolve |
|
|
if cherryhost not in ('localhost', '127.0.0.1', '::1'): |
|
|
|
|
|
cherryhost = '0.0.0.0' |
|
|
|
|
|
try: |
|
|
try: |
|
|
info = socket.getaddrinfo(localhost, None) |
|
|
# Valid user defined name? |
|
|
|
|
|
info = socket.getaddrinfo(cherryhost, None) |
|
|
except: |
|
|
except: |
|
|
info = socket.getaddrinfo('127.0.0.1', None) |
|
|
if cherryhost not in ('localhost', '127.0.0.1', '::1'): |
|
|
localhost = '127.0.0.1' |
|
|
cherryhost = '0.0.0.0' |
|
|
|
|
|
try: |
|
|
|
|
|
info = socket.getaddrinfo(localhost, None) |
|
|
|
|
|
except: |
|
|
|
|
|
info = socket.getaddrinfo('127.0.0.1', None) |
|
|
|
|
|
localhost = '127.0.0.1' |
|
|
for item in info: |
|
|
for item in info: |
|
|
ip = str(item[4][0]) |
|
|
ip = str(item[4][0]) |
|
|
if ip.startswith('169.254.'): |
|
|
if ip.startswith('169.254.'): |
|
@ -1817,4 +1815,4 @@ if __name__ == '__main__': |
|
|
main() |
|
|
main() |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
main() |
|
|
main() |