From 0b7185ce71e4b1c1604a7791800b3a1f0089e669 Mon Sep 17 00:00:00 2001 From: Jeff Bowen <272795+jeffbowen@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:48:30 +1000 Subject: [PATCH] Fix: Add Wi-Fi toggle workaround for macOS Sonoma 14.4+ (#43) On macOS Sonoma 14.4 and later the airport command line tool no longer works. It was being used to disassociate from any wireless networks, a required step before using `ifconfig` to change the MAC address. Now the only way to directly disassociate is with Apple's CoreWLAN framework in Swift or Objective-C. A workaround for this JS-only package is to just turn off the airport device to disassociate from any networks, then turn it back on so we can change the MAC address. The change is able to occur before the airport device reassociates. This should be backwards compatible with older versions of macOS. --- index.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index ad289a7..565d50b 100755 --- a/index.js +++ b/index.js @@ -12,9 +12,6 @@ const quote = require('shell-quote').quote const zeroFill = require('zero-fill') const Winreg = require('winreg') -// Path to Airport binary on macOS 10.7+ -const PATH_TO_AIRPORT = '/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport' - // Windows registry key for interface MAC. Checked on Windows 7 const WIN_REGISTRY_PATH = '\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}' @@ -274,21 +271,16 @@ function setInterfaceMAC (device, mac, port) { if (process.platform === 'darwin') { if (isWirelessPort) { - // Turn on the device, assuming it's an airport device. + // Turn off the device, assuming it's an airport device, to disassociate from any + // networks and then turn it back on so we can change the MAC. try { + cp.execSync(quote(['networksetup', '-setairportpower', device, 'off'])) cp.execSync(quote(['networksetup', '-setairportpower', device, 'on'])) } catch (err) { - throw new Error('Unable to power on wifi device') + throw new Error('Unable to power cycle wifi device') } } - // For some reason this seems to be required even when changing a non-airport device. - try { - cp.execSync(quote([PATH_TO_AIRPORT, '-z'])) - } catch (err) { - throw new Error('Unable to disassociate from wifi networks') - } - // Change the MAC. try { cp.execSync(quote(['ifconfig', device, 'ether', mac])) @@ -302,7 +294,7 @@ function setInterfaceMAC (device, mac, port) { cp.execSync(quote(['networksetup', '-setairportpower', device, 'off'])) cp.execSync(quote(['networksetup', '-setairportpower', device, 'on'])) } catch (err) { - throw new Error('Unable to set restart wifi device') + throw new Error('Unable to restart wifi device') } } } else if (process.platform === 'linux') {