index.js
function randomize (localAdmin) {
  // Randomly assign a VM vendor's MAC address prefix, which should
  // decrease chance of colliding with existing device's addresses.

  const vendors = [
    [ 0x00, 0x05, 0x69 ], // VMware
    [ 0x00, 0x50, 0x56 ], // VMware
    [ 0x00, 0x0C, 0x29 ], // VMware
    [ 0x00, 0x16, 0x3E ], // Xen
    [ 0x00, 0x03, 0xFF ], // Microsoft Hyper-V, Virtual Server, Virtual PC
    [ 0x00, 0x1C, 0x42 ], // Parallels
    [ 0x00, 0x0F, 0x4B ], // Virtual Iron 4
    [ 0x08, 0x00, 0x27 ] // Sun Virtual Box
  ]

  // Windows needs specific prefixes sometimes
  // http://www.wikihow.com/Change-a-Computer's-Mac-Address-in-Windows
  const windowsPrefixes = [
    'D2',
    'D6',
    'DA',
    'DE'
  ]

  const vendor = vendors[random(0, vendors.length - 1)]

  if (process.platform === 'win32') {
    vendor[0] = windowsPrefixes[random(0, 3)]
  }

  const mac = [
    vendor[0],
    vendor[1],
    vendor[2],
    random(0x00, 0x7f),
    random(0x00, 0xff),
    random(0x00, 0xff)
  ]

  if (localAdmin) {
    // Universally administered and locally administered addresses are
    // distinguished by setting the second least significant bit of the
    // most significant byte of the address. If the bit is 0, the address
    // is universally administered. If it is 1, the address is locally
    // administered. In the example address 02-00-00-00-00-01 the most
    // significant byte is 02h. The binary is 00000010 and the second
    // least significant bit is 1. Therefore, it is a locally administered
    // address.[3] The bit is 0 in all OUIs.
    mac[0] |= 2
  }

  return mac
    .map(byte => zeroFill(2, byte.toString(16)))
    .join(':')
    .toUpperCase()
}
function randomize (localAdmin) {
  // Randomly assign a VM vendor's MAC address prefix, which should
  // decrease chance of colliding with existing device's addresses.

  const vendors = [
    [ 0x00, 0x05, 0x69 ], // VMware
    [ 0x00, 0x50, 0x56 ], // VMware
    [ 0x00, 0x0C, 0x29 ], // VMware
    [ 0x00, 0x16, 0x3E ], // Xen
    [ 0x00, 0x03, 0xFF ], // Microsoft Hyper-V, Virtual Server, Virtual PC
    [ 0x00, 0x1C, 0x42 ], // Parallels
    [ 0x00, 0x0F, 0x4B ], // Virtual Iron 4
    [ 0x08, 0x00, 0x27 ] // Sun Virtual Box
  ]

  // Windows needs specific prefixes sometimes
  // http://www.wikihow.com/Change-a-Computer's-Mac-Address-in-Windows
  const windowsPrefixes = [
    'D2',
    'D6',
    'DA',
    'DE'
  ]

  const vendor = vendors[random(0, vendors.length - 1)]

  if (process.platform === 'win32') {
    vendor[0] = windowsPrefixes[random(0, 3)]
  }

  const mac = [
    vendor[0],
    vendor[1],
    vendor[2],
    random(0x00, 0x7f),
    random(0x00, 0xff),
    random(0x00, 0xff)
  ]

  if (localAdmin) {
    // Universally administered and locally administered addresses are
    // distinguished by setting the second least significant bit of the
    // most significant byte of the address. If the bit is 0, the address
    // is universally administered. If it is 1, the address is locally
    // administered. In the example address 02-00-00-00-00-01 the most
    // significant byte is 02h. The binary is 00000010 and the second
    // least significant bit is 1. Therefore, it is a locally administered
    // address.[3] The bit is 0 in all OUIs.
    mac[0] |= 2
  }

  return mac
    .map(byte => zeroFill(2, byte.toString(16)))
    .join(':')
    .toUpperCase()
}
function randomize ( localAdmin ) { // Randomly assign a VM vendor's MAC address prefix, which should // decrease chance of colliding with existing device's addresses. const vendors = [ [ 0x00 , 0x05 , 0x69 ] , // VMware [ 0x00 , 0x50 , 0x56 ] , // VMware [ 0x00 , 0x0C , 0x29 ] , // VMware [ 0x00 , 0x16 , 0x3E ] , // Xen [ 0x00 , 0x03 , 0xFF ] , // Microsoft Hyper-V, Virtual Server, Virtual PC [ 0x00 , 0x1C , 0x42 ] , // Parallels [ 0x00 , 0x0F , 0x4B ] , // Virtual Iron 4 [ 0x08 , 0x00 , 0x27 ] // Sun Virtual Box ] // Windows needs specific prefixes sometimes // http://www.wikihow.com/Change-a-Computer's-Mac-Address-in-Windows const windowsPrefixes = [ 'D2' , 'D6' , 'DA' , 'DE' ] const vendor = vendors [ random ( 0 , vendors . length - 1 ) ] if ( process . platform === 'win32' ) { vendor [ 0 ] = windowsPrefixes [ random ( 0 , 3 ) ] } const mac = [ vendor [ 0 ] , vendor [ 1 ] , vendor [ 2 ] , random ( 0x00 , 0x7f ) , random ( 0x00 , 0xff ) , random ( 0x00 , 0xff ) ] if ( localAdmin ) { // Universally administered and locally administered addresses are // distinguished by setting the second least significant bit of the // most significant byte of the address. If the bit is 0, the address // is universally administered. If it is 1, the address is locally // administered. In the example address 02-00-00-00-00-01 the most // significant byte is 02h. The binary is 00000010 and the second // least significant bit is 1. Therefore, it is a locally administered // address.[3] The bit is 0 in all OUIs. mac [ 0 ] |= 2 } return mac . map ( byte => zeroFill ( 2 , byte . toString ( 16 ) ) ) . join ( ':' ) . toUpperCase ( ) }
Generates and returns a random MAC address.
@param  {boolean} localAdmin  locally administered address
@return {string}
Generates and returns a random MAC address .