def get_local_hostname(self):
"""
Returns the local hostname under which the webinterface can be reached
:return: fully qualified hostname
:rtype: str
"""
import socket
try:
return socket.gethostbyaddr(self.get_local_ip_address())[0] # can fail with default /etc/hosts
except socket.herror:
try:
return socket.gethostbyaddr("127.0.1.1")[0] # in debian based systems hostname is assigned to "127.0.1.1" by default
except socket.herror:
try:
return socket.gethostbyaddr("127.0.0.1")[0] # 'localhost' in most cases
except socket.herror:
return "localhost" # should not happen
评论列表
文章目录