-->
Page 1 of 3

Is there a way to know the mac address of a remote client ?

PostPosted: Tue May 24, 2016 2:27 pm
by Ghassan Yusuf
Dear Friends

I am trying to build an application, in which we have an (esp8266 as a server and as accesspoint) and we have another (esp8266 as a client) that connects to the first esp8266 accesspoint. the server within should only accept specific clients with a certain mac address. any other clients trying to connect with an unknown mac address should be rejected or stoped.

so is there a way in which we can read the mac address of the client at the moment of connection attempt ?

or if there is a better way please guide me.
thanks in advance
Ghassan Yusuf

Re: Is there a way to know the mac address of a remote clien

PostPosted: Wed May 25, 2016 8:39 am
by Cicero
Dunno about arduino, but you can access the sdk directly if you extern C it.

In the SDK there's wifi_softap_get_station_info() that'll give you the IP and MAC's.

A different way would be to use the wifi_set_event_handler_cb, which will be called when the station connects, and you can list the MAC right then (see SDK doc):
Code: Select allcase EVENT_SOFTAPMODE_STACONNECTED:
os_printf("station: " MACSTR "join, AID = %d\n",
MAC2STR(evt->event_info.sta_connected.mac),
evt->event_info.sta_connected.aid);


Maybe you can look for those functions in the arduino libs as a starting point. How you'd kick the station off and ignore them after that though is a different problem. I'd be interested in that as well.

Re: Is there a way to know the mac address of a remote clien

PostPosted: Wed May 25, 2016 7:26 pm
by pgScorpio
Work-around for Arduino esp8266: (Arduino 1.6.9)

Code: Select all#include <ESP8266WiFi.h>

String WiFi_macAddressOf(IPAddress aIp)
{
    if (aIp == WiFi.localIP())
        return WiFi.macAddress();

    if (aIp == WiFi.softAPIP())
        return WiFi.softAPmacAddress();

    return String("00-00-00-00-00-00");
}

void some_client_func()
{

  //get STA MAC if client on STA,  AP MAC if client on AP
    String clientMAC = WiFi_macAddressOf(WiFiClient::localIP());   
 
}


Re: Is there a way to know the mac address of a remote clien

PostPosted: Thu May 26, 2016 8:03 am
by martinayotte
@pgScorpio, your piece of code is returning the ESP MAC, not the client MAC ... :ugeek: