def get_fqhostname():
 l = []
 l.append(socket.getfqdn())
 try:
  addrinfo = socket.getaddrinfo(socket.gethostname(), 0, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.SOL_TCP, socket.AI_CANONNAME)
  for info in addrinfo:
   if (len(info) >= 4):
    l.append(info[3])
 except socket.gaierror:
  pass
 return ((l and l[0]) or None)

def get_fqhostname ( ) : l = [ ] l . append ( socket . getfqdn ( ) ) try : addrinfo = socket . getaddrinfo ( socket . gethostname ( ) , 0 , socket . AF_UNSPEC , socket . SOCK_STREAM , socket . SOL_TCP , socket . AI_CANONNAME ) for info in addrinfo : if ( len ( info ) >= 4 ) : l . append ( info [ 3 ] ) except socket . gaierror : pass return ( ( l and l [ 0 ] ) or None )
returns the fully qualified hostname .