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.

36 lines
788 B

4 years ago
  1. var mdns = require('./')()
  2. mdns.on('warning', function (err) {
  3. console.log(err.stack)
  4. })
  5. mdns.on('response', function (response) {
  6. console.log('got a response packet:', response)
  7. })
  8. mdns.on('query', function (query) {
  9. console.log('got a query packet:', query)
  10. // iterate over all questions to check if we should respond
  11. query.questions.forEach(function (q) {
  12. if (q.type === 'A' && q.name === 'example.local') {
  13. // send an A-record response for example.local
  14. mdns.respond({
  15. answers: [{
  16. name: 'example.local',
  17. type: 'A',
  18. ttl: 300,
  19. data: '192.168.1.5'
  20. }]
  21. })
  22. }
  23. })
  24. })
  25. // lets query for an A-record for example.local
  26. mdns.query({
  27. questions: [{
  28. name: 'example.local',
  29. type: 'A'
  30. }]
  31. })