Solved

VB.net Get all MAC addresses on a computer

Posted on 2014-02-27
4
3,500 Views
Last Modified: 2014-02-28
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
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39893997
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39894490
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
 

Author Closing Comment

by:murbro
ID: 39895126
Thanks very much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question