def _hostname_linux(self):
"""
Returns system hostname.
"""
# Default value found using platform
hostname = platform.node()
try:
# Try to get hostname (FQDN) using 'hostname -f'
(rc, out, err) = exec_command([which('hostname'), '-f'])
if rc == 0:
hostname = out.encode('utf-8').strip()
except Exception:
try:
# Try to get hostname (FQDN) using socket module
(hostname, _, _) = socket.gethostbyaddr(socket.gethostname())
hostname = hostname.strip()
except Exception:
pass
return hostname
评论列表
文章目录