Solved

Get the MAC Address of the physical network adapter

Posted on 2008-06-12
6
842 Views
Last Modified: 2013-11-26
Dear all,
I'm looking for a way to find in VB NET the MAC Address of the network card installed on the pc, I mean not VPN, not any other kind of virtual network adapter, just the MAC of the card inside the pc, even if it's disabled.
Please see the function I wrote below, now I just avoid the NetworkInterfaceType=Tunnel, but how can I be sure to find the physical card? NetworkInterface type has so many values....
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterfacetype.aspx
Public Function GetMacAddress() As String

        Dim theNetworkInterfaces() As System.Net.NetworkInformation.NetworkInterface =   System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()

 

        Dim currentInterface As System.Net.NetworkInformation.NetworkInterface

 

        For Each currentInterface In theNetworkInterfaces

            If currentInterface.NetworkInterfaceType <>   Net.NetworkInformation.NetworkInterfaceType.Tunnel Then

                GetMacAddress = currentInterface.GetPhysicalAddress().ToString()

                Exit For

            End If

        Next

 

    End Function

Open in new window

0
Comment
Question by:aaresearch
  • 3
  • 3
6 Comments
 

Author Comment

by:aaresearch
Comment Utility
Well, the question is not so easy!
0
 
LVL 12

Expert Comment

by:renjurdevan
Comment Utility
using System.Management;
 

string MacAddress = "";
                        try
                        {
                                ManagementClass myManagementClass = new
ManagementClass("Win32_NetworkAdapterConfiguration");
                                ManagementObjectCollection moc = myManagementClass.GetInstances();


                                foreach(ManagementObject mo in moc)
                                {
                                        MacAddress = mo["MacAddress"].ToString();
                                        break;
                                }
}
0
 
LVL 12

Expert Comment

by:renjurdevan
Comment Utility
Imports System.Management

Dim MacAddress  As string

Dim myManagementClass  As New ManagementClass("Win32_NetworkAdapterConfiguration")

 Dim moc As ManagementObjectCollection = myManagementClass.GetInstances()

For Each ManagementObject mo in moc
MacAddress = mo("MacAddress").ToString()
Next

Console.WriteLine (MacAddress )

Make sure that System.Mangement dll included in your application

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:aaresearch
Comment Utility
Dear renjurdean,
I think you did not catch my question.

I have already found the solution to get ALL the MAC of all the network adapter (see the first code I posted), I just want to get the one of the card installed on the pc, only that one.
How can I be sure?

Thanks
0
 
LVL 12

Expert Comment

by:renjurdevan
Comment Utility
moc as ManagementObjectCollection (Collection) so you should enumerate it!
foreach(ManagementObject mo in moc)
                                {
                                        MacAddress = mo["MacAddress"].ToString();
                                       break;
                               }


Check myManagementClass' s methods
0
 

Accepted Solution

by:
aaresearch earned 0 total points
Comment Utility
I rather prefer checking the
currentInterface.NetworkInterfaceType
in the function I wrote, thank you

The exactly what I was trying to explain, that the propoerty had got lots of values, and I'm not sure about their meaning.

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now