Skip to content
Open
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
18 changes: 5 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}'

Expand Down Expand Up @@ -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]))
Expand All @@ -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') {
Expand Down