Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got it people! Me and a guy from the work solve this using this code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;Windows.h&gt; #include &lt;Iphlpapi.h&gt; #include &lt;Assert.h&gt; #pragma comment(lib, "iphlpapi.lib") char* getMAC(); int main(){ char* pMac = getMAC(); system("pause"); free(pMac); } char* getMAC() { PIP_ADAPTER_INFO AdapterInfo; DWORD dwBufLen = sizeof(IP_ADAPTER_INFO); char *mac_addr = (char*)malloc(18); AdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO)); if (AdapterInfo == NULL) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); free(mac_addr); return NULL; // it is safe to call free(NULL) } // Make an initial call to GetAdaptersInfo to get the necessary size into the dwBufLen variable if (GetAdaptersInfo(AdapterInfo, &amp;dwBufLen) == ERROR_BUFFER_OVERFLOW) { free(AdapterInfo); AdapterInfo = (IP_ADAPTER_INFO *) malloc(dwBufLen); if (AdapterInfo == NULL) { printf("Error allocating memory needed to call GetAdaptersinfo\n"); free(mac_addr); return NULL; } } if (GetAdaptersInfo(AdapterInfo, &amp;dwBufLen) == NO_ERROR) { // Contains pointer to current adapter info PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; do { // technically should look at pAdapterInfo-&gt;AddressLength // and not assume it is 6. sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X", pAdapterInfo-&gt;Address[0], pAdapterInfo-&gt;Address[1], pAdapterInfo-&gt;Address[2], pAdapterInfo-&gt;Address[3], pAdapterInfo-&gt;Address[4], pAdapterInfo-&gt;Address[5]); printf("Address: %s, mac: %s\n", pAdapterInfo-&gt;IpAddressList.IpAddress.String, mac_addr); // print them all, return the last one. // return mac_addr; printf("\n"); pAdapterInfo = pAdapterInfo-&gt;Next; } while(pAdapterInfo); } free(AdapterInfo); return mac_addr; // caller must free. } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload