-
Notifications
You must be signed in to change notification settings - Fork 10
MultiCast DNS Lookups
Jared Rice Sr edited this page Jul 1, 2018
·
1 revision
dWeb Library For MultiCast DNS Hostname>IP Lookups.
npm install @distdns/lookup
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.
var lookup = require('@distdns/lookup')
lookup('google.com', function (err, ip) {
console.log(ip) // is resolved using normal DNS (173.194.116.32 on my machine)
})
lookup('dweb.local', function (err, ip) {
console.log(ip) // is resolved using MultiCast DNS (192.168.10.254 on my machine)
})
If you want the node core DNS module to always support MultiCast DNS you can do the following
require('@distdns/lookup/global')
var dns = require('dns')
dns.lookup('dweb.local', function (err, ip) {
console.log(ip) // is resolved using MultiCast DNS (192.168.10.254 on my machine)
})
There is also a command line tool available if you install globally
npm install -g @distdns/lookup
dlookup dweb.local
> 192.168.10.254
Use @distdns/register to register a .local
domain
on another machine.
On one machine (let's pretend it has ip 192.168.10.456)
var register = require('@distdns/register')
register('greetings-martian.local')
On another
var lookup = require('@distdns/lookup')
lookup('greetings-martian.local', function (err, ip) {
console.log(ip) // would print 192.168.10.456
})
MIT