Monday, May 30, 2011

get system MAC Address

Imports System.Collections.Generic
Imports System.Text
Imports System.Security.Cryptography
Imports System.Configuration
Imports System.Management


Public Function GetMACAddress() As String
Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim MACAddress As String = [String].Empty
For Each mo As ManagementObject In moc
If MACAddress = [String].Empty Then
' only return MAC Address from first card
If CBool(mo("IPEnabled")) = True Then
MACAddress = mo("MacAddress").ToString()
End If
End If
mo.Dispose()
Next

MACAddress = MACAddress.Replace(":", "")
Return MACAddress
End Function

No comments:

Post a Comment