Change esp8266 Mac from selected mac

Hi, im using esp8266.
How change esp8266 Mac adress from selected Mac adress after scanning network? like cloning a device Mac adress, but clone 10 first Mac adress and change latest adress to value "FF"

Example, I do scanning network then selected a network have a Mac 0F:12:34:56:78.

After selected a network, an esp8266 automatic change Mac to 0F:12:34:56:FF and start AP Mode

This is my scetch

#include <Arduino.h>
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>

extern "C" { 
  #include "user_interface.h"
}

typedef struct {
  String ssid;
  String bssid_str;
  uint8_t bssid[6];
}

_Network;
_Network _networks[16];
_Network _selectedNetwork;



void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_AP_STA);
  webServer.on("/", handleSetup);
}

void performScan() {
  int n = WiFi.scanNetworks();
  if (n >= 0) {
    for (int i = 0; i < n && i < 16; ++i) {
      _Network network;
      network.ssid = WiFi.SSID(i);
      network.bssid_str = WiFi.BSSIDstr(i);
      for (int j = 0; j < 6; j++) {
        network.bssid[j] = WiFi.BSSID(i)[j];
      }
    }
  }
}

String bytesToStr(const uint8_t* b, uint32_t size) {
  String str;
  const char ZERO = '0';
  const char DOUBLEPOINT = ':';
  for (uint32_t i = 0; i < size; i++) {
    if (b[i] < 0x10) str += ZERO;
    str += String(b[i], HEX);
    if (i < size - 1) str += DOUBLEPOINT;
  }
  return str;
}

String _tempHTML =  "<html><table><tr><th>[T]</th><th>SSID</th><th>BSSID</th></tr>";

void handleSetup() {
  String _html = _tempHTML;
  if (webServer.hasArg("ap")) {
    for (int i = 0; i < 16; i++) {
      if (bytesToStr(_networks[i].bssid, 6) == webServer.arg("ap") ) {
        _selectedNetwork = _networks[i];
      }
    }
  }
  if (webServer.hasArg("hotspot")) {
    if (webServer.arg("hotspot") == "start") {
      hotspot_active = true;
      dnsServer.stop();
      int n = WiFi.softAPdisconnect (true);
      WiFi.softAPConfig(IPAddress(192, 168, 4, 1) , IPAddress(192, 168, 4, 1) , IPAddress(255, 255, 255, 0));
      WiFi.softAP(_selectedNetwork.ssid.c_str());
      dnsServer.start(53, "*", IPAddress(192, 168, 4, 1));
    }
    else if (webServer.arg("hotspot") == "stop") {
      hotspot_active = false;
      dnsServer.stop();
      int n = WiFi.softAPdisconnect (true);
      WiFi.softAPConfig(IPAddress(192, 168, 4, 1) , IPAddress(192, 168, 4, 1) , IPAddress(255, 255, 255, 0));
      WiFi.softAP("Repeater", "repeater");
      dnsServer.start(53, "*", IPAddress(192, 168, 4, 1));
    }
    return;
  }
  if ( bytesToStr(_selectedNetwork.bssid, 6) == bytesToStr(_networks[i].bssid, 6)) {
    _html += "<tr><td><form method='post' action='/?ap=" + bytesToStr(_networks[i].bssid, 6) + "'><button>[O]</button></form></td>";
  }
    else {
    _html += "<tr><td><form method='post' action='/?ap=" + bytesToStr(_networks[i].bssid, 6) + "'><button>-</button></form></td>";
  }
    _html += "<td>" + _networks[i].ssid + "</td><td>" + bytesToStr(_networks[i].bssid, 6) + "</td></tr></html>";
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.