Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS Sequoia+ Private Wifi Address Fix #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var util = require("./lib/util.js");
var lib = {};
var os = require("os");

lib.getMacAddress = require("./lib/getmacaddress.js");
lib.getAllInterfaces = require("./lib/getallinterfaces.js");
Expand Down Expand Up @@ -51,6 +52,9 @@ lib.one = function () {
args.push(name);
var score = 0;
var iface = ifaces[name];
if (os.platform() === 'darwin' && os.release().split('.')[0] >= 24) {
iface.mac = lib.getMacAddress.bind(null, iface);
}
if (typeof iface.mac === "string" && iface.mac !== "00:00:00:00:00:00") {
addresses[name] = iface.mac;
if (iface.ipv4) {
Expand Down Expand Up @@ -108,7 +112,7 @@ lib.all = function (callback) {
var ifaces = lib.networkInterfaces();
var resolve = {};
Object.keys(ifaces).forEach(function (iface) {
if (!ifaces[iface].mac) {
if (!ifaces[iface].mac || (os.platform() === 'darwin' && os.release().split('.')[0] >= 24)) {
resolve[iface] = lib.getMacAddress.bind(null, iface);
}
});
Expand Down
6 changes: 6 additions & 0 deletions lib/getmacaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ switch (os.platform()) {
break;

case 'darwin':
if (os.release().split('.')[0] >= 24){
_getMacAddress = require('./platform/getmacaddress_darwin.js');
} else {
_getMacAddress = require('./platform/getmacaddress_unix.js');
}
break;
case 'sunos':
case 'freebsd':
_getMacAddress = require('./platform/getmacaddress_unix.js');
Expand Down
11 changes: 10 additions & 1 deletion lib/networkinterfaces.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var os = require('os');

var lib = {};

lib.getMacAddress = require("./getmacaddress.js");

// Retrieves all interfaces that do feature some non-internal address.
// This function does NOT employ caching as to reflect the current state
// of the machine accurately.
Expand Down Expand Up @@ -30,7 +34,12 @@ module.exports = function () {
addresses[family] = address.address;
hasAddresses = true;
if (address.mac && address.mac !== '00:00:00:00:00:00') {
addresses.mac = address.mac;
if (os.platform() === 'darwin' && os.release().split('.')[0] >= 24) {
addresses.mac = lib.getMacAddress.bind(null, iface);
}
else{
addresses.mac = address.mac;
}
}
}
});
Expand Down
17 changes: 17 additions & 0 deletions lib/platform/getmacaddress_darwin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* jshint node: true */
var execFile = require('child_process').execFile;

module.exports = function (iface, callback) {
execFile("/usr/sbin/networksetup", ["-getmacaddress", iface], function (err, out) {
if (err) {
callback(err, null);
return;
}
var match = /[a-f0-9]{2}(:[a-f0-9]{2}){5}/.exec(out.toLowerCase());
if (!match) {
callback("did not find a mac address", null);
return;
}
callback(null, match[0].toLowerCase());
});
};