index.js
function setInterfaceMAC (device, mac, port) {
  if (!MAC_ADDRESS_RE.exec(mac)) {
    throw new Error(mac + ' is not a valid MAC address')
  }

  const isWirelessPort = port && port.toLowerCase() === 'wi-fi'

  if (process.platform === 'darwin') {
    if (isWirelessPort) {
      // Turn on the device, assuming it's an airport device.
      try {
        cp.execSync(quote(['networksetup', '-setairportpower', device, 'on']))
      } catch (err) {
        throw new Error('Unable to power on 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]))
    } catch (err) {
      throw new Error('Unable to change MAC address')
    }

    // Restart airport so it will associate with known networks (if any)
    if (isWirelessPort) {
      try {
        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')
      }
    }
  } else if (process.platform === 'linux') {
    // Set the device's mac address.
    // Handles shutting down and starting back up interface.
    try {
      cp.execSync(quote(['ifconfig', device, 'down', 'hw', 'ether', mac]))
      cp.execSync(quote(['ifconfig', device, 'up']))
    } catch (err) {
      throw new Error('Unable to change MAC address')
    }
  } else if (process.platform === 'win32') {
    // Locate adapter's registry and update network address (mac)
    const regKey = new Winreg({
      hive: Winreg.HKLM,
      key: WIN_REGISTRY_PATH
    })

    regKey.keys((err, keys) => {
      if (err) {
        console.log('ERROR: ' + err)
      } else {
        // Loop over all available keys and find the right adapter
        for (let i = 0; i < keys.length; i++) {
          tryWindowsKey(keys[i].key, device, mac)
        }
      }
    })
  }
}
function setInterfaceMAC (device, mac, port) {
  if (!MAC_ADDRESS_RE.exec(mac)) {
    throw new Error(mac + ' is not a valid MAC address')
  }

  const isWirelessPort = port && port.toLowerCase() === 'wi-fi'

  if (process.platform === 'darwin') {
    if (isWirelessPort) {
      // Turn on the device, assuming it's an airport device.
      try {
        cp.execSync(quote(['networksetup', '-setairportpower', device, 'on']))
      } catch (err) {
        throw new Error('Unable to power on 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]))
    } catch (err) {
      throw new Error('Unable to change MAC address')
    }

    // Restart airport so it will associate with known networks (if any)
    if (isWirelessPort) {
      try {
        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')
      }
    }
  } else if (process.platform === 'linux') {
    // Set the device's mac address.
    // Handles shutting down and starting back up interface.
    try {
      cp.execSync(quote(['ifconfig', device, 'down', 'hw', 'ether', mac]))
      cp.execSync(quote(['ifconfig', device, 'up']))
    } catch (err) {
      throw new Error('Unable to change MAC address')
    }
  } else if (process.platform === 'win32') {
    // Locate adapter's registry and update network address (mac)
    const regKey = new Winreg({
      hive: Winreg.HKLM,
      key: WIN_REGISTRY_PATH
    })

    regKey.keys((err, keys) => {
      if (err) {
        console.log('ERROR: ' + err)
      } else {
        // Loop over all available keys and find the right adapter
        for (let i = 0; i < keys.length; i++) {
          tryWindowsKey(keys[i].key, device, mac)
        }
      }
    })
  }
}
function setInterfaceMAC ( device , mac , port ) { if ( ! MAC_ADDRESS_RE . exec ( mac ) ) { throw new Error ( mac + ' is not a valid MAC address' ) } const isWirelessPort = port && port . toLowerCase ( ) === 'wi-fi' if ( process . platform === 'darwin' ) { if ( isWirelessPort ) { // Turn on the device, assuming it's an airport device. try { cp . execSync ( quote ( [ 'networksetup' , '-setairportpower' , device , 'on' ] ) ) } catch ( err ) { throw new Error ( 'Unable to power on 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 ] ) ) } catch ( err ) { throw new Error ( 'Unable to change MAC address' ) } // Restart airport so it will associate with known networks (if any) if ( isWirelessPort ) { try { 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' ) } } } else if ( process . platform === 'linux' ) { // Set the device's mac address. // Handles shutting down and starting back up interface. try { cp . execSync ( quote ( [ 'ifconfig' , device , 'down' , 'hw' , 'ether' , mac ] ) ) cp . execSync ( quote ( [ 'ifconfig' , device , 'up' ] ) ) } catch ( err ) { throw new Error ( 'Unable to change MAC address' ) } } else if ( process . platform === 'win32' ) { // Locate adapter's registry and update network address (mac) const regKey = new Winreg ( { hive : Winreg . HKLM , key : WIN_REGISTRY_PATH } ) regKey . keys ( ( err , keys ) => { if ( err ) { console . log ( 'ERROR: ' + err ) } else { // Loop over all available keys and find the right adapter for ( let i = 0 ; i < keys . length ; i ++ ) { tryWindowsKey ( keys [ i ] . key , device , mac ) } } } ) } }
Sets the mac address for given `device` to `mac`.

Device varies by platform:
OS X, Linux: this is the interface name in ifconfig
Windows: this is the network adapter name in ipconfig

@param {string} device
@param {string} mac
@param {string=} port
Sets the mac address for given device to mac .