MAC address in Compact Framework

百般思念 提交于 2019-12-01 06:12:18

问题


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


回答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




回答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.




回答3:


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
Next



回答4:


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



来源:https://stackoverflow.com/questions/42814/mac-address-in-compact-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!