aaresearch
asked on
Get the MAC Address of the physical network adapter
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=Tunne l, 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
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=Tunne
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
using System.Management;
string MacAddress = "";
try
{
ManagementClass myManagementClass = new
ManagementClass("Win32_Net workAdapte rConfigura tion");
ManagementObjectCollection moc = myManagementClass.GetInsta nces();
foreach(ManagementObject mo in moc)
{
MacAddress = mo["MacAddress"].ToString( );
break;
}
}
string MacAddress = "";
try
{
ManagementClass myManagementClass = new
ManagementClass("Win32_Net
ManagementObjectCollection
foreach(ManagementObject mo in moc)
{
MacAddress = mo["MacAddress"].ToString(
break;
}
}
Imports System.Management
Dim MacAddress As string
Dim myManagementClass As New ManagementClass("Win32_Net workAdapte rConfigura tion")
Dim moc As ManagementObjectCollection = myManagementClass.GetInsta nces()
For Each ManagementObject mo in moc
MacAddress = mo("MacAddress").ToString( )
Next
Console.WriteLine (MacAddress )
Make sure that System.Mangement dll included in your application
Dim MacAddress As string
Dim myManagementClass As New ManagementClass("Win32_Net
Dim moc As ManagementObjectCollection
For Each ManagementObject mo in moc
MacAddress = mo("MacAddress").ToString(
Next
Console.WriteLine (MacAddress )
Make sure that System.Mangement dll included in your application
ASKER
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
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
moc as ManagementObjectCollection (Collection) so you should enumerate it!
foreach(ManagementObject mo in moc)
{
MacAddress = mo["MacAddress"].ToString( );
break;
}
Check myManagementClass' s methods
foreach(ManagementObject mo in moc)
{
MacAddress = mo["MacAddress"].ToString(
break;
}
Check myManagementClass' s methods
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER