Get WiFi MAC address using API on Azure Sphere

stm32 1 Reputation point


Is there a way to get programmatically the MAC address of the WiFi hardware using the API?

Azure Sphere
Azure Sphere
An Azure internet of things security solution including hardware, operating system, and cloud components.
163 questions
{count} votes

2 answers

Sort by: Most helpful
  1. QuantumCache 20,261 Reputation points

    Hello @stm32-0752 , We had a similar kind of discussion in the past , if possible could you please share any User voice feedback being submitted from your side on this request.

    MSDN Similar discussion Thread: MAC address in Ethernet

    Quoted Response from Previous discussion:
    Friday, January 17, 2020 5:13 PM
    At this time there is no command to query the Ethernet interface and list properties associated to IP Address (IPv4) or the MAC address, etc...such as the case for the WiFi interface. This is a product backlog item and will be part of a future release.
    If you have additional feedback or questions, please let me know. I would also suggest to add an entry in the Azure IoT UserVoice to detail specific functionality or features you are looking for or that would be desired.
    If you are looking to access the Ethernet IP Address (IPv4) programmatically there is the following library: getifaddrs
    Please see the following Git Issue related to this:

    [3]: /api/attachments/12901-image.png

  2. James Higgins 316 Reputation points

    You can get the MAC address from the Sphere high-level application, at least with the latest OS/SDK as of this posting:

    #include <ifaddrs.h>
    #include <net/ethernet.h>
    #include <sys/socket.h>
    #include <netpacket/packet.h>
    void getIP(void)
        struct ifaddrs* addr_list;
        struct ifaddrs* it;
        int n;
        const char EthInterface[] = "wlan0";
        if (getifaddrs(&addr_list) < 0) {
            Log_Debug("***** GETIFADDRs failed! ***\n");
        else {
            for (it = addr_list, n = 0; it != NULL; it = it->ifa_next, ++n) {
                if (it->ifa_addr == NULL) {
                if (strncmp(it->ifa_name, EthInterface, sizeof(EthInterface)) == 0) {
                    if (it->ifa_addr->sa_family == AF_INET) {
                        struct sockaddr_in* addr = (struct sockaddr_in*)it->ifa_addr;
                        char* ip_address = inet_ntoa(addr->sin_addr);
                        Log_Debug("**** wlan0 IP found: %s ***\n", ip_address);
                    else if (it->ifa_addr->sa_family == AF_PACKET) {
                        struct sockaddr_ll* mac_addr = (struct sockaddr_ll*)it->ifa_addr;
                        unsigned char* mac = mac_addr->sll_addr;
                        char mac_string[20];
                        sprintf(mac_string, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0],
                            mac[1], mac[2], mac[3], mac[4], mac[5]);
                        Log_Debug("**** wlan0 MAC 1 found: %s ****\n", mac_string);
    0 comments No comments