src_js/fqdn.js
function getFqdnForHostname(hostname, cb) {
  let addressIndex = 0;

  dns.lookup(hostname, { all: true }, function (err, addresses, family) {
    const tryNextAddressOrComplete = (err, fqdn) => {
      addressIndex++;
      if (!err) {
        cb(err, fqdn);
      } else if (addressIndex != addresses.length) {
        getFqdnForIpAddress(addresses[addressIndex].address, tryNextAddressOrComplete);
      } else {
        cb(err);
      }
    };

    if (!err) {
      getFqdnForIpAddress(addresses[addressIndex].address, tryNextAddressOrComplete);
    } else {
      cb(err);
    }
  });
}
function getFqdnForHostname(hostname, cb) {
  let addressIndex = 0;

  dns.lookup(hostname, { all: true }, function (err, addresses, family) {
    const tryNextAddressOrComplete = (err, fqdn) => {
      addressIndex++;
      if (!err) {
        cb(err, fqdn);
      } else if (addressIndex != addresses.length) {
        getFqdnForIpAddress(addresses[addressIndex].address, tryNextAddressOrComplete);
      } else {
        cb(err);
      }
    };

    if (!err) {
      getFqdnForIpAddress(addresses[addressIndex].address, tryNextAddressOrComplete);
    } else {
      cb(err);
    }
  });
}
function getFqdnForHostname ( hostname , cb ) { let addressIndex = 0 ; dns . lookup ( hostname , { all : true } , function ( err , addresses , family ) { const tryNextAddressOrComplete = ( err , fqdn ) => { addressIndex ++ ; if ( ! err ) { cb ( err , fqdn ) ; } else if ( addressIndex != addresses . length ) { getFqdnForIpAddress ( addresses [ addressIndex ] . address , tryNextAddressOrComplete ) ; } else { cb ( err ) ; } } ; if ( ! err ) { getFqdnForIpAddress ( addresses [ addressIndex ] . address , tryNextAddressOrComplete ) ; } else { cb ( err ) ; } } ) ; }
Get the IP addresses for host. For each of the IP addresses, do a reverse lookup, one IP address at a time and take the FQDN from the first successful result.
Get the IP addresses for host . For each of the IP addresses do a reverse lookup one IP address at a time and take the FQDN from the first successful result .