uuid() fix unique mac address issue (Android)

This commit is contained in:
Sebastian Hildebrandt
2023-02-28 11:32:28 +01:00
parent 35f3b3d3c1
commit b5f5c4eceb
4 changed files with 27 additions and 17 deletions
+19 -15
View File
@@ -1047,25 +1047,29 @@ function shell(callback) {
exports.shell = shell;
function getUniqueMacAdresses() {
const ifaces = os.networkInterfaces();
let macs = [];
for (let dev in ifaces) {
if ({}.hasOwnProperty.call(ifaces, dev)) {
ifaces[dev].forEach(function (details) {
if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
const mac = details.mac.toLowerCase();
if (macs.indexOf(mac) === -1) {
macs.push(mac);
try {
const ifaces = os.networkInterfaces();
for (let dev in ifaces) {
if ({}.hasOwnProperty.call(ifaces, dev)) {
ifaces[dev].forEach(function (details) {
if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
const mac = details.mac.toLowerCase();
if (macs.indexOf(mac) === -1) {
macs.push(mac);
}
}
}
});
});
}
}
macs = macs.sort(function (a, b) {
if (a < b) { return -1; }
if (a > b) { return 1; }
return 0;
});
} catch (e) {
macs.push('00:00:00:00:00:00');
}
macs = macs.sort(function (a, b) {
if (a < b) { return -1; }
if (a > b) { return 1; }
return 0;
});
return macs;
}