# MAC Address Finder

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/037/054/medium800/lcds___displays_IMG_4327.jpg?1478551013)

Sometimes finding the MAC address of a wireless device is easy and sometimes it's not. With this project you can find the MAC address of any wireless device in just a few seconds.

What makes this project so simple is the Feather Huzzah. With a few lines of code you can create an access point that other wireless devices can join. Then the Feather will print out the MAC address of that device!

![](https://cdn-learn.adafruit.com/assets/assets/000/036/937/medium800/lcds___displays_2821-01.jpg?1478005641)

In just a short amount of time you can have a device that is&nbsp;a welcome addition to any IT person's tool belt.

# MAC Address Finder

## Parts and Tools

Let's start by getting all the parts together.

![](https://cdn-learn.adafruit.com/assets/assets/000/036/938/medium800/lcds___displays_IMG_4232.jpg?1478005790)

For this project I used the following parts:

- [Feather Huzzah](https://www.adafruit.com/product/2821)
- [FeatherWing OLED](https://www.adafruit.com/product/2900)
- [Lithium Polymer Battery](https://www.adafruit.com/product/1578)

  - Pictured is a 1200 mAh battery but I ended up using a 500 mAh battery I had as it fit inside the case better

- [FeatherWing Doubler](https://www.adafruit.com/product/2890)

  - I could have stacked the OLED and Huzzah but I like the way they look next to each other on the Doubler

- [4 x AA battery case](https://www.adafruit.com/product/830) that I had and was not using

  - I could have 3D printed a case, and might still at some point, but I wanted to put this one to good use

You will also need something similat to the tools pictured above. I mainly used these tools to hack the case to make the Huzzah, OLED and battery fit inside so in reality you can use anything you have to cut away parts of the plastic case.

# MAC Address Finder

## Assembly of the Main Board

There were several things I had to take into account to make it fit inside the case nicely. I played around with the arrangment of the components for a while before settling on the final layout.

We'll start with the Huzzah, OLED and the Doubler.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/036/939/medium800/lcds___displays_IMG_4238.jpg?1478006264)

There's something to be aware of here. I wanted the OLED screen to be on the top, however, when you put it on the top the Lipo connector is on the inside of the board. What I did was arrange everything so that the connector faced out. The only issue with this is that then the OLED is upside down.

Notice in this image the OLED board is upside down.

Luckily for us there is a line of code we can put in to compensate for this and flip the text on the screen so everything is right side up again.

![lcds___displays_IMG_4239.jpg](https://cdn-learn.adafruit.com/assets/assets/000/036/941/medium640/lcds___displays_IMG_4239.jpg?1478006945)

```auto
display.setRotation(2);		//This rotates everything on the screen 180 degrees
```

I started by flipping the doubler over and soldering the Huzzah into place.

![](https://cdn-learn.adafruit.com/assets/assets/000/036/943/medium800/lcds___displays_IMG_4257.jpg?1478007311)

Warning: 

One other consideration I made was the height of the OLED board. Since the Feather has a lipo connector, it is taller than the screen. I&nbsp;wanted the screen to be as close to the front of the case as possible so I couldn't just place it flush with the protoboard.

When I was done soldering the OLED board everything looked like this. _Note that the OLED board is on the right in this image._

![](https://cdn-learn.adafruit.com/assets/assets/000/036/949/medium800/lcds___displays_IMG_4259.jpg?1478008004)

Once everything is put together I uploaded my code to see if everything worked.

Notice the the text on the screen is upside down. Again we'll address this in the code when we get there.

It works!

![](https://cdn-learn.adafruit.com/assets/assets/000/036/951/medium800/lcds___displays_IMG_4263.jpg?1478008286)

# MAC Address Finder

## Preparing the Case

Since the case I chose to use is a AA battery holder it is compartmentalized inside. I needed to open it up and make room for the board, battery and wires. I used small pliers and cutters to break away the parts I didn't need.

I made sure to leave enough of the internal structure&nbsp;to ensure a snug fit so everything didn't bounce around when&nbsp;being moved.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/036/945/medium800/lcds___displays_IMG_4247.jpg?1478007652)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/946/medium800/lcds___displays_IMG_4249.jpg?1478007685)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/947/medium800/lcds___displays_IMG_4268.jpg?1478007782)

Make sure not to damage the area around the power switch. We'll use the switch later to turn the device on and off.

![lcds___displays_IMG_4251.jpg](https://cdn-learn.adafruit.com/assets/assets/000/036/948/medium640/lcds___displays_IMG_4251.jpg?1478007810)

Once I made room for the board I had to cut an opening for the OLED screen. I started with a small hole, that I made with a small phillips head screw driver, around where I thought the center of the screen was and then slowly made it larger and rectangular to better fit the display.

I mostly used a hobby knife going slowly and checking very often to make sure everyhing would line up.

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/036/954/medium800/lcds___displays_IMG_4278.jpg?1478008774)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/955/medium800/lcds___displays_IMG_4279.jpg?1478008784)

Once I got it to the size I wanted, I used the knife moving side to side&nbsp;to put a bevel on each of the four sides of the opening.

# MAC Address Finder

## Connecting the Battery and Switch

One of the last few steps is to connect everything. The battery leads need to be soldered to the switch and to the board.

In the following image you can see the wires I was preparing to solder to the board to provide power. They are connected to the GND and BAT pins.

![](https://cdn-learn.adafruit.com/assets/assets/000/036/950/medium800/lcds___displays_IMG_4273.jpg?1478008219)

I soldered the GND wire directly to the battery and then soldered the red positive wire to the switch. I then also soldered the positive lead from the battery to the switch. I used shrink tubing around the solder points to reenforce them as well as to protect from accidental shorting of the battery.

![](https://cdn-learn.adafruit.com/assets/assets/000/036/952/medium800/lcds___displays_IMG_4277.jpg?1478008521)

When everything was done I tested it again and it worked.

![](https://cdn-learn.adafruit.com/assets/assets/000/036/953/medium800/lcds___displays_IMG_4276.jpg?1478008586)

# MAC Address Finder

## The Code

Now that everything is wired up, it's time for the code.

&nbsp;

```auto
#include &lt;SPI.h&gt;
#include &lt;Wire.h&gt;
#include &lt;Adafruit_GFX.h&gt;
#include &lt;Adafruit_SSD1306.h&gt;
#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266WebServer.h&gt;

extern "C" {
#include&lt;user_interface.h&gt;
}

int connectedClients = 0;

long nextCheck = 0;     //Keeps track of the value of millis to only check for new Clients every 5 seconds.

Adafruit_SSD1306 display = Adafruit_SSD1306();

/* configuration  wifi */
const char *ssid = "MAC Finder";
const char *password = "";

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#endif

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup() {  

  delay(1000);

  //Initialize the display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  display.setRotation(2);
  display.clearDisplay();
  
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.clearDisplay();
  
  initializeAP();  //Setup the Huzzah as an access point
}

void initializeAP() {

  WiFi.softAP(ssid, password);

  //I've noticed that most times the huzzah doesn't let clients connect
  //as soon as it starts up. Here I give it 5 seconds to "warm up"
  //While it does this it prints 
  
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Initializing AP");

  //The two bytes that define the bitmap for the loading dots
  static const unsigned char PROGMEM waiting_dot[] =
  { B00011000,
    B00011000 };
  
  for (int i = 0; i &lt; 10; i++) {

    display.drawBitmap(i * 10, 20, waiting_dot, 8, 2, WHITE);
    display.display();

    delay(1000);
  }
  
  
  display.clearDisplay();
  display.display();
  display.setCursor(0,0);
  
  displaySSID();
  
}

void loop() {

  if (millis() &gt;= nextCheck) {
    
    client_status();

    nextCheck = millis() + 5000;
    
  }
   
}

void displaySSID() {

  display.setTextSize(1);
  display.clearDisplay();
  
  display.setCursor(0,0);
  
  display.print("AP SSID: ");
  
  display.setTextSize(2);
  display.setCursor(0, 10);
  display.println(ssid);
  display.display();
      
}

void client_status() {

  unsigned char number_client;
  struct station_info *stat_info;

  struct ip_addr *IPaddress;
  IPAddress address;
  int i=1;
  
  number_client= wifi_softap_get_station_num(); // Count of stations which are connected to ESP8266 soft-AP
  stat_info = wifi_softap_get_station_info();

  if (number_client &gt; connectedClients) {
     display.setTextSize(1);
     display.clearDisplay();
     display.setCursor(0, 0);
     display.setTextSize(1);
     display.print("Client Connected!");
     display.display();  
     delay(2000);
  } 

  if (number_client &lt; connectedClients) {
     display.setTextSize(1);
     display.clearDisplay();
     display.setCursor(0, 0);
     display.setTextSize(1);
     display.print("Client Disconnected!");
     display.display();
     delay(2000); 

     if (number_client == 0) {
      displaySSID();
      
    }
    
  }
  
  connectedClients = number_client;

  while (stat_info != NULL) {
    
    display.clearDisplay();
    
    display.setCursor(0, 0);
    display.setTextSize(1);
    display.print("Client MAC:");

    display.setCursor(0, 10);
    
    //Get the 6 octets of the client MAC address. Check to see if the value of each octet is less than
    //0xF. If it is we will print a leading 0 to avoid any confusion.
    if (stat_info-&gt;bssid[0] &lt;= 0xF) {
      display.print("0");
    }
    
    display.print(stat_info-&gt;bssid[0],HEX);
    display.print(":");
    
    if (stat_info-&gt;bssid[1] &lt;= 0xF) {
      display.print("0");
    }
    
    display.print(stat_info-&gt;bssid[1],HEX);
    display.print(":");
    
    if (stat_info-&gt;bssid[2] &lt;= 0xF) {
      display.print("0");
    }
    
    display.print(stat_info-&gt;bssid[2],HEX);
    display.print(":");
    
    if (stat_info-&gt;bssid[3] &lt;= 0xF) {
      display.print("0");
    
    }
    display.print(stat_info-&gt;bssid[3],HEX);
    display.print(":");
    
    if (stat_info-&gt;bssid[4] &lt;= 0xF) {
      display.print("0");
    }
    
    display.print(stat_info-&gt;bssid[4],HEX);
    display.print(":");
    
    if (stat_info-&gt;bssid[5] &lt;= 0xF) {
      display.print("0");
    }
    
    display.print(stat_info-&gt;bssid[5],HEX);

    display.display();
    
    stat_info = STAILQ_NEXT(stat_info, next);
    i++;
  
  }
}
```

Upload the code to the Feather Huzzah and test it out. Once you verify it works it's time to put everything together.

# MAC Address Finder

## Putting it all Together

Now it's time to get everyting to close up nicely. For this I fit the board in, saw where I needed more space, shaved some plastic off with the knife, sanded edges down as needed and rinsed and repeated until everything fit.

I actually had to sand down the solder joints on the bottom of the Doubler to get a few more precious millimeteres of space. You don't want to have to force everything in. Doing this means you run the risk of puncturing the lipo battery. Nobody wants that.

When everything was in I added some hot glue to the switch to keep it in place as. I didn't put any on the board as I did not make an opening for a USB cable to charge the battery.

In my case this is fine as I will be removing the board and using it for many different purposes. If, however, you'd like to make one you would do so the same as was done for the OLED screen.

![](https://cdn-learn.adafruit.com/assets/assets/000/036/956/medium800/lcds___displays_IMG_4281.jpg?1478009334)

After some cable managment, i.e. shoving the extra wires anywhere they&nbsp;would fit, I slid the back cover on and it was done!

![](https://cdn-learn.adafruit.com/assets/assets/000/036/957/medium800/lcds___displays_IMG_4284.jpg?1478009427)

![](https://cdn-learn.adafruit.com/assets/assets/000/036/958/medium800/lcds___displays_IMG_4286.jpg?1478009654)

![](https://cdn-learn.adafruit.com/assets/assets/000/037/055/medium800/lcds___displays_IMG_4327.jpg?1478551332)

Now nothing will stop you from getting the MAC address of any wireless device you encounter.


## Featured Products

### Adafruit Feather HUZZAH with ESP8266 - Loose Headers

[Adafruit Feather HUZZAH with ESP8266 - Loose Headers](https://www.adafruit.com/product/2821)
Feather is the new development board from Adafruit, and like its namesake, it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather HUZZAH ESP8266** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2821)
[Related Guides to the Product](https://learn.adafruit.com/products/2821/guides)
### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
### Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather

[Adafruit FeatherWing OLED - 128x32 OLED Add-on For Feather](https://www.adafruit.com/product/2900)
A Feather board without ambition is a Feather board without FeatherWings! This is the **FeatherWing OLED** : it adds a 128x32 monochrome OLED plus 3 user buttons to _any_ Feather main board. Using our [Feather Stacking...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2900)
[Related Guides to the Product](https://learn.adafruit.com/products/2900/guides)
### Lithium Ion Polymer Battery - 3.7v 500mAh

[Lithium Ion Polymer Battery - 3.7v 500mAh](https://www.adafruit.com/product/1578)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 500mAh for a total of about 1.9 Wh. If you need a larger (or smaller!) battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1578)
[Related Guides to the Product](https://learn.adafruit.com/products/1578/guides)
### 4 x AA Battery Holder with On/Off Switch

[4 x AA Battery Holder with On/Off Switch](https://www.adafruit.com/product/830)
Make a nice portable power pack with this 4 x AA battery holder. It fits any alkaline or rechargeable AA batteries in series. There's a snap on cover and an on/off switch which can be handy when wiring to something without a switch.

**New**! We now have 0.1" headers...

In Stock
[Buy Now](https://www.adafruit.com/product/830)
[Related Guides to the Product](https://learn.adafruit.com/products/830/guides)
### Assembled Adafruit FeatherWing OLED

[Assembled Adafruit FeatherWing OLED](https://www.adafruit.com/product/3045)
A Feather board without ambition is a Feather board without FeatherWings! This is the **Assembled FeatherWing OLED** : it adds a 128x32 monochrome OLED plus 3 user buttons to _any_ Feather main board. Comes fully assembled so you can connect a FeatherWing on top of your...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3045)
[Related Guides to the Product](https://learn.adafruit.com/products/3045/guides)

## Related Guides

- [Adafruit Feather HUZZAH ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266.md)
- [Adafruit OLED FeatherWing](https://learn.adafruit.com/adafruit-oled-featherwing.md)
- [CircuitPython 2FA TOTP Authentication Friend](https://learn.adafruit.com/circuitpython-totp-otp-2fa-authy-authenticator-friend.md)
- [Adafruit IO Time Tracking Cube](https://learn.adafruit.com/time-tracking-cube.md)
- [FeatherWing Proto, Doubler  and Tripler](https://learn.adafruit.com/featherwing-proto-and-doubler.md)
- [WiFi OLED Display Badge](https://learn.adafruit.com/digital-display-badge.md)
- [Sensor-Locked Secrets with CircuitPython](https://learn.adafruit.com/sensor-locked-secrets-with-circuitpython.md)
- [Adafruit IO Basics: ESP8266 + Arduino](https://learn.adafruit.com/adafruit-io-basics-esp8266-arduino.md)
- [Mystery Box: Haunted Radio](https://learn.adafruit.com/mystery-box-haunted-radio.md)
- [Wireless NeoPixel Controller](https://learn.adafruit.com/neotrellis-neopixel-controller.md)
- [CircuitPython OLED Watch Clock](https://learn.adafruit.com/circuitpython-oled-watch.md)
- [USB MIDI Host Messenger](https://learn.adafruit.com/usb-midi-host-messenger.md)
- [MicroPython Basics: How to Load MicroPython on a Board](https://learn.adafruit.com/micropython-basics-how-to-load-micropython-on-a-board.md)
- [MicroPython Basics: Blink a LED](https://learn.adafruit.com/micropython-basics-blink-a-led.md)
- [Adafruit IO Home: Security ](https://learn.adafruit.com/adafruit-io-home-security.md)
- [CircuitPython Hardware: SSD1306 OLED Display](https://learn.adafruit.com/micropython-hardware-ssd1306-oled-display.md)
- [Disconnected CO2 Data Logger](https://learn.adafruit.com/disconnected-co2-data-logger.md)
