Get Specific MAC Address





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















My VS2015 VB app is reading the MAC address of the users computer. This has worked well except some users are using laptops with docking stations that assign their own MAC address. The code I am using returns the first one it finds, can a specific one be searched for?



    Dim mc As New ManagementClass(New ManagementPath("Win32_Processor"), New ObjectGetOptions(New ManagementNamedValueCollection()))
Dim moc As ManagementObjectCollection = mc.GetInstances()

mc.Path = New ManagementPath("Win32_NetworkAdapterConfiguration")

moc = mc.GetInstances()

Dim sMac As String = String.Empty

For Each mo As ManagementObject In moc

If (mo.GetPropertyValue("IPEnabled") = True) Then

If (sMac = String.Empty) Then

sMac = mo.GetPropertyValue("MacAddress").ToString()

End If

End If

Next









share|improve this question























  • Have you tried to output the ServiceName to determine any difference between the laptop and dockstation (mo.GetPropertyValue("ServiceName"))?

    – Code Pope
    Jan 3 at 15:22











  • I tried capturing the relevant services, was not able to determine the difference between a laptop and docking station without knowing more about each device.

    – Terabithia
    Jan 24 at 6:50


















2















My VS2015 VB app is reading the MAC address of the users computer. This has worked well except some users are using laptops with docking stations that assign their own MAC address. The code I am using returns the first one it finds, can a specific one be searched for?



    Dim mc As New ManagementClass(New ManagementPath("Win32_Processor"), New ObjectGetOptions(New ManagementNamedValueCollection()))
Dim moc As ManagementObjectCollection = mc.GetInstances()

mc.Path = New ManagementPath("Win32_NetworkAdapterConfiguration")

moc = mc.GetInstances()

Dim sMac As String = String.Empty

For Each mo As ManagementObject In moc

If (mo.GetPropertyValue("IPEnabled") = True) Then

If (sMac = String.Empty) Then

sMac = mo.GetPropertyValue("MacAddress").ToString()

End If

End If

Next









share|improve this question























  • Have you tried to output the ServiceName to determine any difference between the laptop and dockstation (mo.GetPropertyValue("ServiceName"))?

    – Code Pope
    Jan 3 at 15:22











  • I tried capturing the relevant services, was not able to determine the difference between a laptop and docking station without knowing more about each device.

    – Terabithia
    Jan 24 at 6:50














2












2








2








My VS2015 VB app is reading the MAC address of the users computer. This has worked well except some users are using laptops with docking stations that assign their own MAC address. The code I am using returns the first one it finds, can a specific one be searched for?



    Dim mc As New ManagementClass(New ManagementPath("Win32_Processor"), New ObjectGetOptions(New ManagementNamedValueCollection()))
Dim moc As ManagementObjectCollection = mc.GetInstances()

mc.Path = New ManagementPath("Win32_NetworkAdapterConfiguration")

moc = mc.GetInstances()

Dim sMac As String = String.Empty

For Each mo As ManagementObject In moc

If (mo.GetPropertyValue("IPEnabled") = True) Then

If (sMac = String.Empty) Then

sMac = mo.GetPropertyValue("MacAddress").ToString()

End If

End If

Next









share|improve this question














My VS2015 VB app is reading the MAC address of the users computer. This has worked well except some users are using laptops with docking stations that assign their own MAC address. The code I am using returns the first one it finds, can a specific one be searched for?



    Dim mc As New ManagementClass(New ManagementPath("Win32_Processor"), New ObjectGetOptions(New ManagementNamedValueCollection()))
Dim moc As ManagementObjectCollection = mc.GetInstances()

mc.Path = New ManagementPath("Win32_NetworkAdapterConfiguration")

moc = mc.GetInstances()

Dim sMac As String = String.Empty

For Each mo As ManagementObject In moc

If (mo.GetPropertyValue("IPEnabled") = True) Then

If (sMac = String.Empty) Then

sMac = mo.GetPropertyValue("MacAddress").ToString()

End If

End If

Next






vb.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 15:04









TerabithiaTerabithia

348




348













  • Have you tried to output the ServiceName to determine any difference between the laptop and dockstation (mo.GetPropertyValue("ServiceName"))?

    – Code Pope
    Jan 3 at 15:22











  • I tried capturing the relevant services, was not able to determine the difference between a laptop and docking station without knowing more about each device.

    – Terabithia
    Jan 24 at 6:50



















  • Have you tried to output the ServiceName to determine any difference between the laptop and dockstation (mo.GetPropertyValue("ServiceName"))?

    – Code Pope
    Jan 3 at 15:22











  • I tried capturing the relevant services, was not able to determine the difference between a laptop and docking station without knowing more about each device.

    – Terabithia
    Jan 24 at 6:50

















Have you tried to output the ServiceName to determine any difference between the laptop and dockstation (mo.GetPropertyValue("ServiceName"))?

– Code Pope
Jan 3 at 15:22





Have you tried to output the ServiceName to determine any difference between the laptop and dockstation (mo.GetPropertyValue("ServiceName"))?

– Code Pope
Jan 3 at 15:22













I tried capturing the relevant services, was not able to determine the difference between a laptop and docking station without knowing more about each device.

– Terabithia
Jan 24 at 6:50





I tried capturing the relevant services, was not able to determine the difference between a laptop and docking station without knowing more about each device.

– Terabithia
Jan 24 at 6:50












1 Answer
1






active

oldest

votes


















1














This method is using System.Net.NetworkInformation.NetworkInterface instead of directly querying the WMI interface.



It returns informations on all the current Network Interfaces, except the Loopback interface, where the Operational Status is UP. This usually filters the Teredo and ISATAP interfaces and, of course, all the Network Interfaces that are not currently active.



The NetworkInterfaceType could also be used to filter other specific interface type, the NetworkInterfaceType.Wireless80211 for example.



I'm proposing this variant because it's simpler to modify/expand when required.



Each instance of the NetInterfaceMac class povides:




  • The Interface human-friendly description

  • The IPV4 addresses of the Interface

  • The MAC address if string format ("BF:D1:E8:8C:2B:A4")

  • The MAC address bytes




Public Class NetInterfaceMac
Public Property InterfaceDescription() As String
Public Property IPAddress() As IPAddress
Public Property MacAddress() As String
Public Property MacAddressBytes() As Byte()
End Class

Public Shared Function GetNetworkMACAddresses() As List(Of NetInterfaceMac)
Dim Macs As New List(Of NetInterfaceMac)()

Dim NetInterfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

Macs.AddRange(NetInterfaces.Where(
Function(ni) ni.NetworkInterfaceType <> NetworkInterfaceType.Loopback AndAlso
ni.OperationalStatus = OperationalStatus.Up).
Select(Function(ni) New NetInterfaceMac() With {
.IPAddress = ni.GetIPProperties().UnicastAddresses?.
Where(Function(ip) ip.IsDnsEligible = True)?.Select(Function(ip) ip.Address).ToArray(),
.InterfaceDescription = ni.Description,
.MacAddress = ni.GetPhysicalAddress().GetAddressBytes().
Select(Function(b) b.ToString("X")).Aggregate(Function(s1, s2) s2 + ":" + s1),
.MacAddressBytes = ni.GetPhysicalAddress().GetAddressBytes()
}))

Return Macs
End Function


Sample call:



Dim Macs As List(Of NetInterfaceMac) = GetNetworkMACAddresses()





share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024865%2fget-specific-mac-address%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This method is using System.Net.NetworkInformation.NetworkInterface instead of directly querying the WMI interface.



    It returns informations on all the current Network Interfaces, except the Loopback interface, where the Operational Status is UP. This usually filters the Teredo and ISATAP interfaces and, of course, all the Network Interfaces that are not currently active.



    The NetworkInterfaceType could also be used to filter other specific interface type, the NetworkInterfaceType.Wireless80211 for example.



    I'm proposing this variant because it's simpler to modify/expand when required.



    Each instance of the NetInterfaceMac class povides:




    • The Interface human-friendly description

    • The IPV4 addresses of the Interface

    • The MAC address if string format ("BF:D1:E8:8C:2B:A4")

    • The MAC address bytes




    Public Class NetInterfaceMac
    Public Property InterfaceDescription() As String
    Public Property IPAddress() As IPAddress
    Public Property MacAddress() As String
    Public Property MacAddressBytes() As Byte()
    End Class

    Public Shared Function GetNetworkMACAddresses() As List(Of NetInterfaceMac)
    Dim Macs As New List(Of NetInterfaceMac)()

    Dim NetInterfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

    Macs.AddRange(NetInterfaces.Where(
    Function(ni) ni.NetworkInterfaceType <> NetworkInterfaceType.Loopback AndAlso
    ni.OperationalStatus = OperationalStatus.Up).
    Select(Function(ni) New NetInterfaceMac() With {
    .IPAddress = ni.GetIPProperties().UnicastAddresses?.
    Where(Function(ip) ip.IsDnsEligible = True)?.Select(Function(ip) ip.Address).ToArray(),
    .InterfaceDescription = ni.Description,
    .MacAddress = ni.GetPhysicalAddress().GetAddressBytes().
    Select(Function(b) b.ToString("X")).Aggregate(Function(s1, s2) s2 + ":" + s1),
    .MacAddressBytes = ni.GetPhysicalAddress().GetAddressBytes()
    }))

    Return Macs
    End Function


    Sample call:



    Dim Macs As List(Of NetInterfaceMac) = GetNetworkMACAddresses()





    share|improve this answer






























      1














      This method is using System.Net.NetworkInformation.NetworkInterface instead of directly querying the WMI interface.



      It returns informations on all the current Network Interfaces, except the Loopback interface, where the Operational Status is UP. This usually filters the Teredo and ISATAP interfaces and, of course, all the Network Interfaces that are not currently active.



      The NetworkInterfaceType could also be used to filter other specific interface type, the NetworkInterfaceType.Wireless80211 for example.



      I'm proposing this variant because it's simpler to modify/expand when required.



      Each instance of the NetInterfaceMac class povides:




      • The Interface human-friendly description

      • The IPV4 addresses of the Interface

      • The MAC address if string format ("BF:D1:E8:8C:2B:A4")

      • The MAC address bytes




      Public Class NetInterfaceMac
      Public Property InterfaceDescription() As String
      Public Property IPAddress() As IPAddress
      Public Property MacAddress() As String
      Public Property MacAddressBytes() As Byte()
      End Class

      Public Shared Function GetNetworkMACAddresses() As List(Of NetInterfaceMac)
      Dim Macs As New List(Of NetInterfaceMac)()

      Dim NetInterfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

      Macs.AddRange(NetInterfaces.Where(
      Function(ni) ni.NetworkInterfaceType <> NetworkInterfaceType.Loopback AndAlso
      ni.OperationalStatus = OperationalStatus.Up).
      Select(Function(ni) New NetInterfaceMac() With {
      .IPAddress = ni.GetIPProperties().UnicastAddresses?.
      Where(Function(ip) ip.IsDnsEligible = True)?.Select(Function(ip) ip.Address).ToArray(),
      .InterfaceDescription = ni.Description,
      .MacAddress = ni.GetPhysicalAddress().GetAddressBytes().
      Select(Function(b) b.ToString("X")).Aggregate(Function(s1, s2) s2 + ":" + s1),
      .MacAddressBytes = ni.GetPhysicalAddress().GetAddressBytes()
      }))

      Return Macs
      End Function


      Sample call:



      Dim Macs As List(Of NetInterfaceMac) = GetNetworkMACAddresses()





      share|improve this answer




























        1












        1








        1







        This method is using System.Net.NetworkInformation.NetworkInterface instead of directly querying the WMI interface.



        It returns informations on all the current Network Interfaces, except the Loopback interface, where the Operational Status is UP. This usually filters the Teredo and ISATAP interfaces and, of course, all the Network Interfaces that are not currently active.



        The NetworkInterfaceType could also be used to filter other specific interface type, the NetworkInterfaceType.Wireless80211 for example.



        I'm proposing this variant because it's simpler to modify/expand when required.



        Each instance of the NetInterfaceMac class povides:




        • The Interface human-friendly description

        • The IPV4 addresses of the Interface

        • The MAC address if string format ("BF:D1:E8:8C:2B:A4")

        • The MAC address bytes




        Public Class NetInterfaceMac
        Public Property InterfaceDescription() As String
        Public Property IPAddress() As IPAddress
        Public Property MacAddress() As String
        Public Property MacAddressBytes() As Byte()
        End Class

        Public Shared Function GetNetworkMACAddresses() As List(Of NetInterfaceMac)
        Dim Macs As New List(Of NetInterfaceMac)()

        Dim NetInterfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

        Macs.AddRange(NetInterfaces.Where(
        Function(ni) ni.NetworkInterfaceType <> NetworkInterfaceType.Loopback AndAlso
        ni.OperationalStatus = OperationalStatus.Up).
        Select(Function(ni) New NetInterfaceMac() With {
        .IPAddress = ni.GetIPProperties().UnicastAddresses?.
        Where(Function(ip) ip.IsDnsEligible = True)?.Select(Function(ip) ip.Address).ToArray(),
        .InterfaceDescription = ni.Description,
        .MacAddress = ni.GetPhysicalAddress().GetAddressBytes().
        Select(Function(b) b.ToString("X")).Aggregate(Function(s1, s2) s2 + ":" + s1),
        .MacAddressBytes = ni.GetPhysicalAddress().GetAddressBytes()
        }))

        Return Macs
        End Function


        Sample call:



        Dim Macs As List(Of NetInterfaceMac) = GetNetworkMACAddresses()





        share|improve this answer















        This method is using System.Net.NetworkInformation.NetworkInterface instead of directly querying the WMI interface.



        It returns informations on all the current Network Interfaces, except the Loopback interface, where the Operational Status is UP. This usually filters the Teredo and ISATAP interfaces and, of course, all the Network Interfaces that are not currently active.



        The NetworkInterfaceType could also be used to filter other specific interface type, the NetworkInterfaceType.Wireless80211 for example.



        I'm proposing this variant because it's simpler to modify/expand when required.



        Each instance of the NetInterfaceMac class povides:




        • The Interface human-friendly description

        • The IPV4 addresses of the Interface

        • The MAC address if string format ("BF:D1:E8:8C:2B:A4")

        • The MAC address bytes




        Public Class NetInterfaceMac
        Public Property InterfaceDescription() As String
        Public Property IPAddress() As IPAddress
        Public Property MacAddress() As String
        Public Property MacAddressBytes() As Byte()
        End Class

        Public Shared Function GetNetworkMACAddresses() As List(Of NetInterfaceMac)
        Dim Macs As New List(Of NetInterfaceMac)()

        Dim NetInterfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

        Macs.AddRange(NetInterfaces.Where(
        Function(ni) ni.NetworkInterfaceType <> NetworkInterfaceType.Loopback AndAlso
        ni.OperationalStatus = OperationalStatus.Up).
        Select(Function(ni) New NetInterfaceMac() With {
        .IPAddress = ni.GetIPProperties().UnicastAddresses?.
        Where(Function(ip) ip.IsDnsEligible = True)?.Select(Function(ip) ip.Address).ToArray(),
        .InterfaceDescription = ni.Description,
        .MacAddress = ni.GetPhysicalAddress().GetAddressBytes().
        Select(Function(b) b.ToString("X")).Aggregate(Function(s1, s2) s2 + ":" + s1),
        .MacAddressBytes = ni.GetPhysicalAddress().GetAddressBytes()
        }))

        Return Macs
        End Function


        Sample call:



        Dim Macs As List(Of NetInterfaceMac) = GetNetworkMACAddresses()






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 3 at 17:49

























        answered Jan 3 at 17:06









        JimiJimi

        9,76542035




        9,76542035
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024865%2fget-specific-mac-address%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]