-->
Page 1 of 1

How to find out the default gateway(router) mac address

PostPosted: Thu Mar 22, 2018 7:32 am
by J.Silva
Hello,

I need to find out the mac address of the router with the ESP8266 :shock:

I have the IP with this command:
Code: Select allSerial.println(WiFi.gatewayIP());


I also used a function to check all the devices connected to the ESP8266

Code: Select allvoid 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();
  stat_info = wifi_softap_get_station_info();
 
  Serial.print(" Total Connected Clients are = ");
  Serial.println(number_client);
 
    while (stat_info != NULL) {
   
      IPaddress = &stat_info->ip;
      address = IPaddress->addr;
     
      Serial.print("client= ");
     
      Serial.print(i);
      Serial.print(" IP adress is = ");
      Serial.print((address));
      Serial.print(" with MAC adress is = ");
     
      Serial.print(stat_info->bssid[0],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[1],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[2],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[3],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[4],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[5],HEX);Serial.print(" ");
     
      stat_info = STAILQ_NEXT(stat_info, next);
      i++;
      Serial.println();
    }
   
  delay(500);
}


but I didn't manage to get the mac address of the router

is there any way?

Re: How to find out the default gateway(router) mac address

PostPosted: Fri Mar 30, 2018 2:42 am
by PatrykW
Code: Select allSerial.println(WiFi.BSSIDstr());

This will show you the MAC address of the AP you're connected to.
Should work for you, assuming you're connected directly to your router.

Re: How to find out the default gateway(router) mac address

PostPosted: Sat Mar 31, 2018 3:35 pm
by J.Silva
Thank you so much for letting me know about that!

However I was testing this, I printed it in Serial COM,
and then checked it in ARP table, and the mac addresses don't match :shock:

I will create a new post for this, I believe it's more appropriate

Thanks :D

Re: How to find out the default gateway(router) mac address

PostPosted: Sun Apr 01, 2018 3:14 am
by PatrykW
Remember that MAC is assigned to an interface. It has very little to do with the IP.
If you have say Ethernet, 2.4GHz WLAN and 5GHz WLAN, you might well have 3 different MACs