def get_fqdn():
"""
Return the current fqdn of the machine, trying hard to return a meaningful
name.
In particular, it means working against a NetworkManager bug which seems to
make C{getfqdn} return localhost6.localdomain6 for machine without a domain
since Maverick.
"""
fqdn = socket.getfqdn()
if "localhost" in fqdn:
# Try the heavy artillery
fqdn = socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET,
socket.SOCK_DGRAM, socket.IPPROTO_IP,
socket.AI_CANONNAME)[0][3]
if "localhost" in fqdn:
# Another fallback
fqdn = socket.gethostname()
return fqdn
评论列表
文章目录