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

+2  A: 

Add a reference to System.Management.dll and use something like:

Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
 If mo.Item("IPEnabled") = True Then
  ListBox1.Items.Add("MAC address " & mo.Item("MacAddress").ToString())
 End If
Greg Roberts
+2  A: 

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


Did none of those help?

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

Matt Hamilton

I can't use WMI or install OpenNETCF. Is there another way using with ONLY the Compact Framework?

+5  A: 

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/ 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


See my answer to this similar question...

As far as I can see from the docs the System.Net.NetworkInformation.NetworkInterface class is supported in the compact framework, so it should meet your needs.

Stu Mackellar

If you can access the registry, try to find your adapter MAC Address under the LOCAL_MACHINE\Comm\PCI\***\Parms\MacAddress.

It may be a quick and dirty solution that doesn't involve the use of WMI or OpenNETCF ...

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.