• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3828
  • Last Modified:

VB.net Get all MAC addresses on a computer

What VB.net code do I use to  get MAC addresses of all the physical NICs in user's computer and then if any of the MACs matches with the one that you have in your database then its a known user.

The code would be similar to the following, which I am told gets the last MAC address:

  Friend Function GetMACAddress() As String

        Dim mc As ManagementClass = 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.Equals(String.Empty)) Then
                If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()

                mo.Dispose()
            End If
            MACAddress = MACAddress.Replace(":", String.Empty)

        Next
        Return MACAddress
    End Function

Open in new window

0
Murray Brown
Asked:
Murray Brown
1 Solution
 
käµfm³d 👽Commented:
Why not use the Process class to invoke the getmac command? You could redirect the output of the process instance, and then parse the output for each MAC address.
0
 
CodeCruiserCommented:
Try following function

  Friend Function GetMACAddress() As String

        Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim moc As ManagementObjectCollection = mc.GetInstances()
        Dim MACAddress As String = String.Empty
        For Each mo As ManagementObject In moc
               If CBool(mo("IPEnabled")) Then MACAddress &= mo("MacAddress").ToString() & ";"
               mo.Dispose()
        Next
        Return MACAddress.Trim.Trim(";").Trim
    End Function

Open in new window



This will return you all the MAC addresses in computer. You can then do a .Contains on it to see if the MAC address that you have matches any of these. You may have to remove the IPEnabled condition. Experiment with it by comparing the output of this function with getmac command.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now