index.js
function MarantzDenonUPnPDiscovery(callback) {
    var that = this;
    var foundDevices = {};                                                      // only report a device once

    // create socket
    var socket = dgram.createSocket({type: 'udp4', reuseAddr: true});
    socket.unref();
    const search = new Buffer([
        'M-SEARCH * HTTP/1.1',
        'HOST: 239.255.255.250:1900',
        'ST: upnp:rootdevice',
        'MAN: "ssdp:discover"',
        'MX: 3',
        '',
        ''
    ].join('\r\n'));

    socket.on('error', function(err) {
        console.log(`server error:\n${err.stack}`);
        socket.close();
    });

    socket.on('message', function(message, rinfo) {
        var messageString = message.toString();
        console.log(messageString);
        if (messageString.match(/(d|D)enon/)) {
            location = messageString.match(/LOCATION: (.*?)(\d+\.\d+\.\d+\.\d+)(.*)/);
            if (location) {
                arp.getMAC(location[2], function(err, mac) {                    // lookup ip on the arp table to get the MacAddress
                    if (!err) {
                        if (foundDevices[mac]) {                                // only report foind devices once
                            return;
                        }
                        var device = {
                            friendlyName: '',
                            ip: location[2],
                            location: (location[1] + location[2] + location[3]).trim(),
                            mac: mac,
                            manufacturer: 'Unknown Manufacturer',
                            model: 'Unknown Model'
                        };
                        foundDevices[mac] = device;
                        that.getUPnPInfo(device, function() {
                            if (device.manufacturer == 'Unknown Manufacturer') { // still no info?
                                that.getDeviceInfo(device, function() {callback(null, device);}, 80);
                            } else {
                                callback(null, device);
                            }
                        });
                    }
                });
            }
        }
    });

    socket.on('listening', function() {
        socket.addMembership('239.255.255.250');
        socket.setMulticastTTL(4);
        const address = socket.address();
        console.log(`server listening ${address.address}:${address.port}`);
        socket.send(search, 0, search.length, 1900, '239.255.255.250');
        setTimeout(function() {socket.close();}, 5000);
    });

    socket.bind(0);
}
function MarantzDenonUPnPDiscovery(callback) {
    var that = this;
    var foundDevices = {};                                                      // only report a device once

    // create socket
    var socket = dgram.createSocket({type: 'udp4', reuseAddr: true});
    socket.unref();
    const search = new Buffer([
        'M-SEARCH * HTTP/1.1',
        'HOST: 239.255.255.250:1900',
        'ST: upnp:rootdevice',
        'MAN: "ssdp:discover"',
        'MX: 3',
        '',
        ''
    ].join('\r\n'));

    socket.on('error', function(err) {
        console.log(`server error:\n${err.stack}`);
        socket.close();
    });

    socket.on('message', function(message, rinfo) {
        var messageString = message.toString();
        console.log(messageString);
        if (messageString.match(/(d|D)enon/)) {
            location = messageString.match(/LOCATION: (.*?)(\d+\.\d+\.\d+\.\d+)(.*)/);
            if (location) {
                arp.getMAC(location[2], function(err, mac) {                    // lookup ip on the arp table to get the MacAddress
                    if (!err) {
                        if (foundDevices[mac]) {                                // only report foind devices once
                            return;
                        }
                        var device = {
                            friendlyName: '',
                            ip: location[2],
                            location: (location[1] + location[2] + location[3]).trim(),
                            mac: mac,
                            manufacturer: 'Unknown Manufacturer',
                            model: 'Unknown Model'
                        };
                        foundDevices[mac] = device;
                        that.getUPnPInfo(device, function() {
                            if (device.manufacturer == 'Unknown Manufacturer') { // still no info?
                                that.getDeviceInfo(device, function() {callback(null, device);}, 80);
                            } else {
                                callback(null, device);
                            }
                        });
                    }
                });
            }
        }
    });

    socket.on('listening', function() {
        socket.addMembership('239.255.255.250');
        socket.setMulticastTTL(4);
        const address = socket.address();
        console.log(`server listening ${address.address}:${address.port}`);
        socket.send(search, 0, search.length, 1900, '239.255.255.250');
        setTimeout(function() {socket.close();}, 5000);
    });

    socket.bind(0);
}
function MarantzDenonUPnPDiscovery ( callback ) { var that = this ; var foundDevices = { } ; // only report a device once // create socket var socket = dgram . createSocket ( { type : 'udp4' , reuseAddr : true } ) ; socket . unref ( ) ; const search = new Buffer ( [ 'M-SEARCH * HTTP/1.1' , 'HOST: 239.255.255.250:1900' , 'ST: upnp:rootdevice' , 'MAN: "ssdp:discover"' , 'MX: 3' , '' , '' ] . join ( '\r\n' ) ) ; socket . on ( 'error' , function ( err ) { console . log ( ` \n ${ err . stack } ` ) ; socket . close ( ) ; } ) ; socket . on ( 'message' , function ( message , rinfo ) { var messageString = message . toString ( ) ; console . log ( messageString ) ; if ( messageString . match ( / (d|D)enon / ) ) { location = messageString . match ( / LOCATION: (.*?)(\d+\.\d+\.\d+\.\d+)(.*) / ) ; if ( location ) { arp . getMAC ( location [ 2 ] , function ( err , mac ) { // lookup ip on the arp table to get the MacAddress if ( ! err ) { if ( foundDevices [ mac ] ) { // only report foind devices once return ; } var device = { friendlyName : '' , ip : location [ 2 ] , location : ( location [ 1 ] + location [ 2 ] + location [ 3 ] ) . trim ( ) , mac : mac , manufacturer : 'Unknown Manufacturer' , model : 'Unknown Model' } ; foundDevices [ mac ] = device ; that . getUPnPInfo ( device , function ( ) { if ( device . manufacturer == 'Unknown Manufacturer' ) { // still no info? that . getDeviceInfo ( device , function ( ) { callback ( null , device ) ; } , 80 ) ; } else { callback ( null , device ) ; } } ) ; } } ) ; } } } ) ; socket . on ( 'listening' , function ( ) { socket . addMembership ( '239.255.255.250' ) ; socket . setMulticastTTL ( 4 ) ; const address = socket . address ( ) ; console . log ( ` ${ address . address } ${ address . port } ` ) ; socket . send ( search , 0 , search . length , 1900 , '239.255.255.250' ) ; setTimeout ( function ( ) { socket . close ( ) ; } , 5000 ) ; } ) ; socket . bind ( 0 ) ; }
Find Denon and marantz devices advertising their services by upnp.
@param {function} callback .
@constructor
Find Denon and marantz devices advertising their services by upnp .