I’m developing a Node.js application where I’m discovering devices on my local network using SSDP and mDNS. I have successfully implemented device discovery with the following code snippet:
const SSDP = require('node-ssdp').Client;
const mdns = require('mdns');
// SSDP Discovery
const ssdpClient = new SSDP();
ssdpClient.on('response', function (headers, statusCode, rinfo) {
console.log('SSDP Device found:');
console.log('Headers:', headers);
console.log('Status:', statusCode);
console.log('Remote Info:', rinfo);
});
console.log('Starting SSDP search...');
ssdpClient.search('ssdp:all');
// mDNS Discovery
const mdnsBrowser = mdns.createBrowser(mdns.tcp('http'));
mdnsBrowser.on('serviceUp', function (service) {
console.log('mDNS Service up:', service);
});
mdnsBrowser.on('serviceDown', function (service) {
console.log('mDNS Service down:', service);
});
console.log('Starting mDNS search...');
mdnsBrowser.start();
// Extend the timeout to 20 seconds to ensure we catch all devices
setTimeout(function () {
ssdpClient.stop();
mdnsBrowser.stop();
console.log('Search stopped.');
}, 20000);
While this code effectively logs information for all discovered devices, I need to retrieve the MAC address
of a specific device identified through SSDP or mDNS, not just its general information. How can I modify this code to specifically obtain the MAC address of a particular device?
Web Dev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.