ESP8266 Get MAC Address

Knowing the MAC address of an ESP8266 can be useful. When you set one up on a network you initially don't know what IP address has been allocated to it. If you use an IP scanner to find the IP addresses on your network it can be difficult to determine what node is which. The MAC address is unique to each node and will not change and so if you know it you can usually fine the right node in the IP address listing as the MAC address is normally listed along side.

This Arduino sketch finds the MAC address of the attached ESP8266…


#include <ESP8266WiFi.h>
 
String MAC_Address(){
  uint8_t MAC_array[6];
  String MAC="";
  WiFi.macAddress(MAC_array);
  for(uint8_t i=0;i<6;i++){
    if(MAC_array[i]<0x10)MAC+="0";
    MAC+=String(MAC_array[i],HEX);
    if(i<5)MAC+=":";
  }
  MAC.toUpperCase();
  return MAC;
}
 
 
void setup() {
  Serial.begin(115200);
  Serial.println();
  String MACaddr;
  MACaddr= MAC_Address();
  Serial.print("\nMAC Address is ");
  Serial.println(MACaddr);
}
 
void loop() {
}