Skip to content

Instantly share code, notes, and snippets.

@leodr
Created November 4, 2021 23:57
Show Gist options
  • Save leodr/e14a1b7aaa9438f3b4e19ad6793b672f to your computer and use it in GitHub Desktop.
Save leodr/e14a1b7aaa9438f3b4e19ad6793b672f to your computer and use it in GitHub Desktop.
Changes the networking MAC address on macOS.
const { exec } = require("child_process");
let macAddress;
do {
macAddress = "XX:XX:XX:XX:XX:XX".replace(/X/g, () =>
"0123456789abcdef".charAt(Math.floor(Math.random() * 16))
);
} while (parseInt(macAddress[1], 16) % 2 !== 0);
console.log(macAddress);
const cmd = "sudo ifconfig en0 ether " + macAddress;
console.log(cmd);
exec(cmd, (err, stdout, stderr) => {
console.log(stdout);
if (err || stderr) console.error("error: " + stderr);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment