Read MAC Address from network adapter in .NET

前端 未结 7 1789
梦谈多话
梦谈多话 2020-11-29 07:02

I\'d like to be able to read the mac address from the first active network adapter using VB.net or C# (using .NET 3.5 SP1) for a winform application

相关标签:
7条回答
  • 2020-11-29 07:37

    It looks like this is an old post but I know that you will run into this thread looking for help so here is what I did today to get the MAC addresses of all the network interfaces in my Laptop.

    First of all you have to import the following

    Imports System.Net.NetworkInformation
    

    This is the function that returns all the MAC addresses in an string array

    Private Function GetMAC() As String()
        Dim MACAddresses(0) As String
        Dim i As Integer = 0
        Dim NIC As NetworkInterface
    
        For Each NIC In NetworkInterface.GetAllNetworkInterfaces
            ReDim Preserve MACAddresses(i)
            MACAddresses(i) = String.Format("{0}", NIC.GetPhysicalAddress())
            i += 1
        Next
        Return MACAddresses
    End Function
    
    0 讨论(0)
提交回复
热议问题