lookup-multicast-dns
Lookup an ip for a hostname using multicast-dns if it is a .local domain or otherwise use the dns module
npm install lookup-multicast-dns
OSX supports resolving .local domains using mdns per default but unfortunately not
all other platforms have as good support for it. On Ubuntu you currently have to install and run the avahi-daemon
which is why I wrote this module that allows you to always resolve them from javascript without relying on os support.
Usage
var lookup = require('lookup-multicast-dns')
lookup('google.com', function (err, ip) {
console.log(ip)
})
lookup('brunhilde.local', function (err, ip) {
console.log(ip)
})
If you want the node core dns module to always support multicast-dns you can do the following
require('lookup-multicast-dns/global')
var dns = require('dns')
dns.lookup('brunhilde.local', function (err, ip) {
console.log(ip)
})
Command line tool
There is also a command line tool available if you install globally
npm install -g lookup-multicast-dns
lookup-multicast-dns brunhilde.local
> 192.168.10.254
Related
Use register-multicast-dns to register a .local domain
on another machine.
On one machine (let's pretend it has ip 192.168.10.456)
var register = require('register-multicast-dns')
register('hello-world.local')
On another
var lookup = require('lookup-multicast-dns')
lookup('hello-world.local', function (err, ip) {
console.log(ip)
})
License
MIT