How to get MAC address of another devices within single network?

Hello, I’ve got an BW16 RTL8720DN board. Based upon file “…\Arduino15\packages\realtek\hardware\AmebaD\3.1.5\system\component\common\api\network\src\ping_test.c”
I was able to send ICMP ping to another device in my home network. Most interesting function is void ping_test(void *param). Now I need to get MAC address of pinged device, because I’m planning to develop a simple scanner of network. Does anybody have a clue, how to get MAC?

Currently I’m on Windows 11, using Arduino IDE + SDK 3.1.5

Hello @Strong_Ampere ! If you just want to obtain the MAC address on the spot, you can use the arp -a <IP ADDRESS> command in your command prompt terminal.

Alternatively, you might find our Wifi Mac Monitor example useful. For this example, you’ll have to enable CONFIG_EXAMPLE_MAC_MONITOR in ambd_arduino/Arduino_package/hardware/system/project/realtek_amebaD_va0_example/inc/inc_hp/platform_opts.h (line 221). i.e. change from 0 to 1.

To run the example, use AT commands to interact with the board. Execute the following commands to activate your board as an AP:

ATW3=<AP NAME>
ATW4=<PASSWORD>
ATWA

Your board will turn into an AP and you will observe the MAC addresses of devices connected to your AP.

1 Like

I also realized, that there is no possibility to obtain a MAC just from ping command. Only ARP is the key to success.

  ip4_addr_t ip;
    struct eth_addr *mac = NULL;
    const ip4_addr_t *unused = NULL;
    IP4_ADDR(&ip, 192, 168, 0, 15);

    const auto index = etharp_find_addr(NULL, &ip, &mac, &unused);
    if (index >= 0 && mac != NULL) {
        printf("%x:%x:%x:%x:%x:%x\n", mac->addr[0], mac->addr[1], mac->addr[2], mac->addr[3], mac->addr[4], mac->addr[5]);
    } else {
        printf("ARP find failed, index = %d, mac = %p\n", index, mac);
    }

Moreover, I’ve found quite good example, how to send a ICMP ping, it is located here:
C:\Users<username>\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.5\system\component\common\api\network\src\ping_test.c

it only requires minor adjustments to fit my needs, and that all :slight_smile:

2 Likes