Mobile Device MAc Address
I have a windows mobile project.I want to get the MAC address or numbers of the device for securitiy of my software. My project 开发者_JS百科is in Windows Ce and Windows Mobile 6 (two project). How can I get the value from the mobile device? (I looked the same questions but they are about Bluetooth MAC address and some devices don't have it)
Call the GetAdaptersInfo
API. It returns an IP_ADAPTER_INFO
which is a buffer of all infos for the device's adapters. The IP_ADAPTER_INFO
contains a member called Address
which is the adapter's MAC address.
Since I take a lot time to find a VB.NET way to this,so I post this for anyone that could be useful.
<DllImport("iphlpapi.dll", SetLastError:=True)> _
Public Shared Function GetAdaptersInfo(ByVal info As Byte(), ByRef size As UInteger) As Integer
End Function
Public Shared Function GetMacAddress() As String
Dim num As UInteger = 0UI
GetAdaptersInfo(Nothing, num)
Dim array As Byte() = New Byte(CInt(num) - 1) {}
Dim adaptersInfo As Integer = GetAdaptersInfo(array, num)
If adaptersInfo = 0 Then
Dim macAddress As String = ""
Dim macLength As Integer = BitConverter.ToInt32(array, 400)
macAddress = BitConverter.ToString(array, 404, macLength)
macAddress = macAddress.Replace("-", ":")
Return macAddress
Else
Return ""
End If
精彩评论