code: def getfqdn(name=''):
      
      name = name.strip()
      if not name or name == '0.0.0.0':
          name = gethostname()
      try:
          hostname, aliases, ipaddrs = gethostbyaddr(name)
      except error:
          pass
      else:
          aliases.insert(0, hostname)
          for name in aliases:
              if '.' in name:
                  break
          else:
              name = hostname
      return name
docs: Get fully qualified domain name from name.
  
      An empty argument is interpreted as meaning the local host.
  
      First the hostname returned by gethostbyaddr() is checked, then
      possibly existing aliases. In case no FQDN is available, hostname
      from gethostname() is returned.