You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dnsResolve.js 638B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Module dependencies.
  3. */
  4. var dns = require('dns');
  5. /**
  6. * Module exports.
  7. */
  8. module.exports = dnsResolve;
  9. dnsResolve.async = true;
  10. /**
  11. * Resolves the given DNS hostname into an IP address, and returns it in the dot
  12. * separated format as a string.
  13. *
  14. * Example:
  15. *
  16. * ``` js
  17. * dnsResolve("home.netscape.com")
  18. * // returns the string "198.95.249.79".
  19. * ```
  20. *
  21. * @param {String} host hostname to resolve
  22. * @return {String} resolved IP address
  23. */
  24. function dnsResolve (host, fn) {
  25. var family = 4;
  26. dns.lookup(host, family, function (err, ip) {
  27. if (err) return fn(err);
  28. fn(null, ip || '127.0.0.1');
  29. });
  30. }