Skip to content

Commit

Permalink
Change method to retrieve broadcast addresses and update probe to use…
Browse files Browse the repository at this point in the history
… them
  • Loading branch information
mozoloa committed Dec 21, 2024
1 parent 77a21cd commit 4b3b622
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,54 @@ class BAirInstance extends InstanceBase {
this.checkFeedbacks(...Object.keys(this.blinkingFB))
}

/**
* Get broadcast addresses for all local IPv4 interfaces.
* @returns {string[]} An array of broadcast addresses (e.g., ["192.168.1.255", ...]).
*/
getBroadcastAddresses() {
const os = require('os');
const interfaces = os.networkInterfaces();
const broadcastAddresses = [];

for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
// Calculate broadcast address by replacing the last octet with 255
const parts = iface.address.split('.');
parts[3] = '255';
broadcastAddresses.push(parts.join('.'));
}
}
}

return broadcastAddresses;
}


/**
*
* network scanner interval
*/
probe() {
const broadcastAddresses = this.getBroadcastAddresses();

if (!(this.probeCount % 6)) {
// scan every 30 seconds
this.scanPort.send(
{
address: '/xinfo',
args: [],
},
'255.255.255.255',
10024
)
// Scan every 30 seconds
for (const broadcast of broadcastAddresses) {
this.scanPort.send(
{
address: '/xinfo',
args: [],
},
broadcast,
10024
);
}
}
this.probeCount++
this.probeCount++;
}


/**
* Gather list of local mixer IP numbers and names
*/
Expand Down

0 comments on commit 4b3b622

Please sign in to comment.