MAC address in Compact Framework

11,033

Solution 1

1.4 of the OpenNETCF code gets the information from the following P/Invoke call:

    [DllImport ("iphlpapi.dll", SetLastError=true)]
    public static extern int GetAdaptersInfo( byte[] ip, ref int size );

The physical address (returned as MAC address) I think is around about index 400 - 408 of the byte array after the call. So you can just use that directly if you don't want to use OpenNETCF (why though? OpenNETCF rocks more than stone henge!)

Wonderful P/Invoke.net gives a full example here.

Oh and to properly answer your question:

only using the Compact Framework

You cant. That's life with CF, if you want some fun try sending data with a socket synchronously with a timeout. :D

Solution 2

Here are the first three hits from a Google search for "MAC address in Compact Framework:

  1. http://arjunachith.blogspot.com/2007/08/retrieving-mac-address-in-compact.html
  2. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=920417&SiteID=1
  3. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=188787&SiteID=1

Did none of those help?

Two out of three point to OpenNETCF as a way to do it.

Share:
11,033
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    How can I get the MAC Address using only the compact framework?

  • ctacke
    ctacke over 15 years
    That would be a complete luck situation if it's there. I just checked 4 devices, including one that actually has a PCI bus, and none of them have the MacAddress in the registry. Querying the value from NDIS is the only reliable way to get this.
  • Trisped
    Trisped about 11 years
    .Net CF (Compact Framework) does not have the System.Management namespace.