multicast-dns
multicast-dns
Low level multicast-dns implementation in pure javascript
npm install multicast-dnsUsage
var mdns = require('multicast-dns')()
mdns.on('response', function(response) {
console.log('got a response packet:', response)
})
mdns.on('query', function(query) {
console.log('got a query packet:', query)
})
// lets query for an A record for 'brunhilde.local'
mdns.query({
questions:[{
name: 'brunhilde.local',
type: 'A'
}]
})Running the above (change brunhilde.local to your-own-hostname.local) will print an echo of the query packet first
And then a response packet
CLI
API
A packet has the following format
Currently data from SRV, A, PTR, TXT, AAAA and HINFO records is passed
mdns = multicastdns([options])
Creates a new mdns instance. Options can contain the following
mdns.on('query', (packet, rinfo))
Emitted when a query packet is received.
mdns.on('response', (packet, rinfo))
Emitted when a response packet is received.
The response might not be a response to a query you send as this is the result of someone multicasting a response.
mdns.query(packet, [cb])
Send a dns query. The callback will be called when the packet was sent.
The following shorthands are equivalent
mdns.respond(packet, [cb])
Send a dns response. The callback will be called when the packet was sent.
The following shorthands are equivalent
mdns.destroy()
Destroy the mdns instance. Closes the udp socket.
Development
To start hacking on this module you can use this example to get started
License
MIT
Last updated
Was this helpful?