7.2.5 • Published 2 years ago

multicast-dns v7.2.5

Weekly downloads
7,955,632
License
MIT
Repository
github
Last release
2 years ago

multicast-dns

Low level multicast-dns implementation in pure javascript

npm install multicast-dns

build status

Usage

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

got a query packet: { type: 'query',
  questions: [ { name: 'brunhilde.local', type: 'A', class: 1 } ],
  answers: [],
  authorities: [],
  additionals: [] }

And then a response packet

got a response packet: { type: 'response',
  questions: [],
  answers:
   [ { name: 'brunhilde.local',
       type: 'A',
       class: 'IN',
       ttl: 120,
       flush: true,
       data: '192.168.1.5' } ],
  authorities: [],
  additionals:
   [ { name: 'brunhilde.local',
       type: 'A',
       class: 'IN',
       ttl: 120,
       flush: true,
       data: '192.168.1.5' },
     { name: 'brunhilde.local',
       type: 'AAAA',
       class: 'IN',
       ttl: 120,
       flush: true,
       data: 'fe80::5ef9:38ff:fe8c:ceaa' } ] }

CLI

npm install -g multicast-dns
multicast-dns brunhilde.local
> 192.168.1.1

API

A packet has the following format

{
  questions: [{
    name: 'brunhilde.local',
    type: 'A'
  }],
  answers: [{
    name: 'brunhilde.local',
    type: 'A',
    ttl: seconds,
    data: (record type specific data)
  }],
  additionals: [
    (same format as answers)
  ],
  authorities: [
    (same format as answers)
  ]
}

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

{
  multicast: true // use udp multicasting
  interface: '192.168.0.2' // explicitly specify a network interface. defaults to all
  port: 5353, // set the udp port
  ip: '224.0.0.251', // set the udp ip
  ttl: 255, // set the multicast ttl
  loopback: true, // receive your own packets
  reuseAddr: true // set the reuseAddr option when creating the socket (requires node >=0.11.13)
}

mdns.on('query', (packet, rinfo))

Emitted when a query packet is received.

mdns.on('query', function(query) {
  if (query.questions[0] && query.questions[0].name === 'brunhilde.local') {
    mdns.respond(someResponse) // see below
  }
})

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.query('brunhilde.local', 'A')
mdns.query([{name:'brunhilde.local', type:'A'}])
mdns.query({
  questions: [{name:'brunhilde.local', type:'A'}]
})

mdns.respond(packet, [cb])

Send a dns response. The callback will be called when the packet was sent.

// reply with a SRV and a A record as an answer
mdns.respond({
  answers: [{
    name: 'my-service',
    type: 'SRV',
    data: {
      port: 9999,
      weight: 0,
      priority: 10,
      target: 'my-service.example.com'
    }
  }, {
    name: 'brunhilde.local',
    type: 'A',
    ttl: 300,
    data: '192.168.1.5'
  }]
})

The following shorthands are equivalent

mdns.respond([{name:'brunhilde.local', type:'A', data:'192.158.1.5'}])
mdns.respond({
  answers: [{name:'brunhilde.local', type:'A', data:'192.158.1.5'}]
})

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

git clone git://github.com/mafintosh/multicast-dns.git
npm install
node example.js
node cli.js $(hostname).local

License

MIT

bonjourcomponennenttvuedragdropuploadimageselectron-bonjourbb-chat@frxf/frxf@texttree/demo-bsa-reference-rcl@l1nyanm1ng/react-picture-viewercthpb-plugin-social@companion-module/bmd-atemlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29@infinitebrahmanuniverse/nolb-multiccclibyarntesthyperpass-sdkxhirasklif-ui-kitsklif-api@everything-registry/sub-chunk-2217@314oner_npm/universal-components-librarynode-red-contrib-superpower-test-lypp149-tablesklif-uidweb-dns-discoveryelyeu-shelly-node5emily-webpackeasyplayer-mydyson-nodedwswarm-discoverydynamic-ui-practicefizzle-clistyle-guide-mainfastlion-picture-vieweresphome-native-apinextjs-storiesmynanceflowable-bpmn-modelerfreemambazeroconfhomebridge-toyama-tmesh-pluginhomewizard-energy-apihomebridge-plugin-ewelink-cubehomespun-discoveryhomebridge-hoobs-shellyhomebridge-sanremo-cubehomebridge-elyeu-shelly-node6homebridge-elyeu-shelly-node-gui1homebridge-iteadhot-zone-vuegoogle-home-notify-clientjesusdemoxz-as-a-servicejulien-easy-modalipfs-mdnswot-testing-dns-sdimage-storieshello_test_my_webpackhelp-widgetmdns-cast-browsermdns-listener-advancedmdns-proxymdns-resolvermdns-resolver-timeoutmdns-swarmmdns-wifi-location@internetarchive/dweb-mirror@hyperswarm/discoverymagnamearum@img-arena/img-ui-mui-theme@img-arena/ui-core@mathu01/gdpr-consent@makepro-x/bonjour-service@mayuriachewad/pickupbiz-npm-packagenewdemo1@lozzychops/dropdown-menu@lukyer/shellies-ngnet-functions-pm2nbonjour2nbonjourmy-webpack-number-test-demomy-library-button@marinaga/bananizemavectramatternodelevilibtest17levilibtest18levilibtest21levilibtest22levilibtest23levimultiplatform10levimultiplatformtestlevimultitestlevikotlinlib
7.2.5

2 years ago

7.2.4

3 years ago

7.2.3

3 years ago

7.2.2

4 years ago

7.2.1

4 years ago

7.2.0

6 years ago

7.1.1

6 years ago

7.1.0

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.2.3

6 years ago

6.2.2

6 years ago

6.2.1

6 years ago

6.2.0

6 years ago

6.1.1

7 years ago

6.1.0

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.5.0

8 years ago

5.4.0

8 years ago

5.3.1

8 years ago

5.3.0

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.2

8 years ago

5.0.1

8 years ago

5.0.0

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.0

9 years ago

2.2.0

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.0

9 years ago