How to get MAC address of a client (a PC) on ESP8266 in STA mode (both connect to the same router)

Hi, I'm wanna creat a small project followed by this tutorial (https://www.instructables.com/ESP8266-and-Python-Communication-ForNoobs/?fbclid=IwAR2afNnKZRuwAgqIrsxzDo5gjv5LuxUzj3UwpuXdCYmIezHTofWaGIgy-sM), which can potray in this pic below.

**Brief description: esp collected data from sensors. Then, esp connects to a router and creates a localhost server and starts to waiting a request. Everytime a client (pc) (connected to same router) sends a request to that localhost, esp runs the desired code and then returns the result as an http request.

**The code is work well, but I want to add more rule: Only 1 pc can request to localhost and get the data from esp (Ex, we have 2 pc: pc1 and pc2 connect to the router, but only pc1 can get the data from localhost, if pc2 try to go to the localhost, esp won't send the data).

I try to do that by get the MAC address of client, which send a request to localhost and check if it similar with pc1 MAC address, if not, esp will not returns the data. But I dont know how to check the MAC address of client (the pc) on ESP8266 in STA mode. Can anyone help me? Thank you so much for your help

**My code so far:

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>

WiFiServer server(80); //port 80
WiFiClient client;
String path;

void start(String ssid, String pass) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);

  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP: ");
  Serial.println(WiFi.localIP());

  server.begin();

}

bool isReq = false;


void CheckReq() {
  client = server.available();
  if (!client) {
    return;
  }
  Serial.println("");
  Serial.print("FIND NEW REQUEST - ");
  while (client.connected() && !client.available()) {
    delay(1);
  }

  String req = client.readStringUntil('\r');
  int addr_start = req.indexOf(' ');
  int addr_end = req.indexOf(' ', addr_start + 1);
  if (addr_start == -1 || addr_end == -1) {
    Serial.print("Invalid request: ");
    Serial.println(req);
    return;
  }
  req = req.substring(addr_start + 1, addr_end);
  Serial.print("Requested Path: ");
  Serial.println(req);

  path = req;
  isReq = true;
  client.flush();
}

void waitNewReq () {
  do {
    CheckReq();
  }
  while (!isReq);
  isReq = false;
}

void returnStr(String data1, String data2) {
  String s1;
  s1 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
  s1 += data1;
  s1 += " ";
  s1 += data2;
  client.print(s1);
}

void returnData(float data1, int data2) {
  returnStr(String(data1), String(data2));
}

String getPath() {
  return path;
}
#include <ESP8266WiFi.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include "func.h"

const char* ssid = "ssid";
const char* pass = "pas*******";
const int TEMP_PIN = 4;
const int LIGHT_PIN = 14;

OneWire oneWire(TEMP_PIN);
DallasTemperature sensors(&oneWire);

void setup () {
  Serial.begin(115200);
  start(ssid,pass);
  pinMode(LIGHT_PIN, INPUT);
}

void loop() {
  sensors.requestTemperatures();
  Serial.print("Temp: ");
  Serial.println(sensors.getTempCByIndex(0));
  Serial.print("Light: ");
  Serial.println(digitalRead(LIGHT_PIN));

  waitNewReq();
  returnData(sensors.getTempCByIndex(0),digitalRead(LIGHT_PIN));
}

This is not any more secure than to just check the IP address. So either add a password protection or introduce some kind of token. The MAC address is nothing more than a token. On today's hardware a MAC address can be changed without a problem.

Going out on a limb here, but I think the concept of a MAC address only exists for the connection between two Ethernet entities ... i.e. between PC / Router or ESP / Router. With the router between the ESP and PC, you're now in IP Address land.

The Data Link Layer (layer 2 of the OSI 7 layer model) uses the MAC (Media Access Control) address in providing point-to-point connectivity between network nodes over the physical connections provided by the underlying Physical layer. i.e. the MAC address uniquely identifies a node on the network like the address of a house

edit: to display the MAC address try

  Serial.print("ESP8266 Board MAC Address:  ");
  Serial.println(WiFi.macAddress());

Hmm, I dont wanna add a password or something like this (cause I wanna build a testbed, use a attack tool to attack to the web to observe what is happen). Is is possible to send the data from esp to the pc (I mean, the esp send data driectly to just 1 pc), not through a web server or localhost ?

I want to check the MAC address of the client (pc), not the esp. How can I do it

you require a program similar to the ARP command available on PCs etc
As far as I can see the ESP libraries do not implement this functionality and you would require access to low level communication functions to write the code yourself.

if you wish to ensure that only ESPs with specific MAC addresses can connect have a look at ESP-NOW whre the transmitter maintains a list of receiver MAC addresses

thank you so muchh for your help :smiling_face_with_three_hearts: