title: How to get 'primary' MAC address on windows?
body: <p>I want my program to get primary MAC address on my user's computer and send it to my server when user login, so I can limit my program only run on 2 devices (like evernote)</p>
  
  <p>I tried to use <a href="https://msdn.microsoft.com/en-us/library/aa365915(v=vs.85).aspx" rel="nofollow noreferrer">GetAdaptersAddresses function</a>, but it gave me multiple network adapter information. Here's the output:</p>
  
  <blockquote>
  <pre><code>    ...
      Length of the IP_ADAPTER_ADDRESS struct: 376
      IfIndex (IPv4 interface): 4
      Adapter name: {1DF5C314-BE85-4804-B653-D3E5F98F5231}
      Number of Unicast Addresses: 2
      No Anycast Addresses
      Number of Multicast Addresses: 10
      Number of DNS Server Addresses: 3
      DNS Suffix:
      Description: VMware Virtual Ethernet Adapter for VMnet8
      Friendly name: VMware Network Adapter VMnet8
      Physical address: 00-50-56-C0-00-08
      Flags: 453
      Mtu: 1500
      IfType: 6
      OperStatus: 1
      Ipv6IfIndex (IPv6 interface): 4
      ZoneIndices (hex): 4 4 4 4 1 1 1 1 1 1 1 1 1 1 0 1
      Transmit link speed: 100000000
      Receive link speed: 100000000
      Number of IP Adapter Prefix entries: 8
  
      Length of the IP_ADAPTER_ADDRESS struct: 376
      IfIndex (IPv4 interface): 9
      Adapter name: {65CE3D53-968E-410E-8C47-E0BACBC3D42B}
      Number of Unicast Addresses: 2
      No Anycast Addresses
      Number of Multicast Addresses: 10
      Number of DNS Server Addresses: 3
      DNS Suffix:
      Description: Hyper-V Virtual Ethernet Adapter
      Friendly name: vEthernet (      
      Physical address: **BC-85-56-8F-3B-0B**
      Flags: 453
      Mtu: 1500
      IfType: 6
      OperStatus: 1
      Ipv6IfIndex (IPv6 interface): 9
      ZoneIndices (hex): 9 9 9 9 1 1 1 1 1 1 1 1 1 1 0 1
      Transmit link speed: 54000000
      Receive link speed: 54000000
      Number of IP Adapter Prefix entries: 8
      ...
  </code></pre>
  </blockquote>
  
  <p>I can see the second one on my route. It is the one I'm looking for, but how can I distinguish it from the others?</p>
  
  <p>What I want is a single MAC which should be:</p>
  
  <ol>
  <li>The network adapter should have <strong>connectivity</strong> (I can see it from 'View your network properties' on Windows, but don't know how to pragmatically get it)</li>
  <li>Not the 'VMware Virtual Ethernet Adapter for VMnet8'</li>
  <li>Program can get the same MAC after restart, even after OS re-installation</li>
  </ol>
  
  <p>I found <a href="https://www.codeproject.com/Articles/64975/Detect-Internet-Network-Availability" rel="nofollow noreferrer">Detect-Internet-Network-Availability</a>, maybe network stat on network adapter interface could be one of the factors to identify the 'primary' network adapter I want. But it was written in C#.</p>
  
  <p>Any ideas?</p>