Main Page - Log in -

MAC address

From Noah.org

Jump to: navigation, search


Contents

MAC address

Organizationally Unique Identifier, or OUI

The first three bytes of a MAC address are the Organizationally Unique Identifier, or OUI. These addresses are assigned by the IEEE Registration Authority. You pay about $2000 for a reserved block.

locally administered address

A locally administered MAC address is similar to a LAN IP address (10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16). You can make up your own locally administered address and can be sure that it will not collide with any hardware on your network that use a factory burned-in MAC address. Locally administered addresses are useful when creating virtual machines or virtual network interfaces.

The second bit of the first byte of a MAC address determines the type of OUI. If the bit is 0 then it is an OUI globally assigned by the IEEE; if the bit is 1 then it is a locally administered MAC address.

Create a OUI by whatever scheme you like, then logically OR it with 02:00:00:00:00:00, and then logically AND it with fe:ff:ff:ff:ff:ff, and you will have a locally administered address. The first OR pattern sets bit 2 of the first byte; the second AND pattern clears bit 1 of the first byte (unicast, not multicast).

The following MAC address pattern satisfies the OUI requirements:

4e:4f:41:48:00:00

change MAC address

The following sets eth0 interface to use a locally administered address:

ifconfig eth0 hw ether 02:00:00:00:00:01

or using iproute2 commands you would use the following:

ip link set dev eth0 address 02:00:00:00:00:01

Arduino MAC and IP address hog

This is a DHCP tester made for use with an Arduino and Ethernet Shield.

/*
  MAC and IP address hog
  
  This sketch repeatedly requests MAC addresses from DHCP.
  A new MAC address is given for each request.
  Circuit:
  * Ethernet shield attached to pins 10, 11, 12, 13
 
  created 2012-07-25
  by Noah Spurrier
 */

#include <SPI.h>
#include <Ethernet.h>


// MAC address template.
// Note that this is a "locally administered MAC address".
// Note that the following is true: "0x4e|0x02 == 0x4e"
byte mac[] = { 0x4e, 0x4f, 0x41, 0x48, 0x0, 0x0 };

void setup() {
  // Open serial port.
  Serial.begin(9600);
  // Wait for serial port to connect. Needed for Leonardo only.
  while (!Serial) ;

  delay (1000); 
  Serial.println();
  Serial.println("Begin hogging MAC:IP address leases on DHCP.");
  for (mac[4] = 0; mac[4] <= 254; mac[4]++){
    for (mac[5] = 0; mac[5] <= 254; mac[5]++){ 
      Serial.print("MAC: ");
      for (byte thisByte = 0; thisByte < 6; thisByte++) {
        // print the value of each byte of the MAC address:
        Serial.print(mac[thisByte], HEX);
        if (thisByte < 5) Serial.print(":");
      }
      Serial.print(", ");
      Serial.print("IP: ");
      // start new Ethernet connection. See http://arduino.cc/it/Reference/Ethernet
      if (Ethernet.begin(mac) == 0) {
        Serial.print("ERROR: Failed to get IP address from DHCP.");
        delay(1000);
      }
      else {
        for (byte thisByte = 0; thisByte < 4; thisByte++) {
          // print the value of each byte of the IP address:
          Serial.print(Ethernet.localIP()[thisByte], DEC);
          if (thisByte < 3) Serial.print("."); 
        }
      }
      Serial.println();
      delay(3000);
    }
  }
}

void loop() {

}