0

I need to determine the MAC address of the network adapter that is currently in use.

On my PC (where I test my code) multiple network adapters seem to be active. One from the network adapter that is connected to the LAN (that's the one I would be interested in), and 2 virtual network adapters registered by VMWare. And when - for test purposes - I connect my iPhone I get one more adapter.

Unfortunately a lot of "solutions" I found list the MAC addresses in some random order, so the active one might be at any place in the list.

I tried various methods, e.g.

Can anybody give my a hint which way to look? I am using Delphi2010, this might be a problem for the post related to XE6.

Edit: It turns out there is no such thing as a single active network adapter. So there will not be a proper answer for this question and - in my view - this issue can be closed. I tried to make that by writing an answer, but that seems to violate so-policies and the post was deleted. Anyway, thanks for your help.

Community
  • 1
  • 1
ralfiii
  • 584
  • 4
  • 13
  • 1
    What do you mean by, "_currently in use_?" All active network adapters are currently in use, and traffic will use the correct one based on the destination IP address. – Ron Maupin Oct 05 '16 at 15:42
  • I think that best way is using WMI. See this samples: Looking for a MAC address of a physical adapter (http://stackoverflow.com/a/10597252/17487) and How to get MAC address in windows7? (http://stackoverflow.com/a/3270482/17487) – Germán Estévez -Neftalí- Oct 05 '16 at 15:50
  • To detect the active adapter, try to launch this query: "select * from Win32_PerfFormattedData_Tcpip_NetworkInterface WHERE BytesReceivedPersec>0" – Germán Estévez -Neftalí- Oct 05 '16 at 15:58
  • 1
    Multiple adapters can be "currently in use" at the same time. It all depends on which networks the PC is currently connected to, and what the PC's traffic on each network is like at any given moment. – Remy Lebeau Oct 05 '16 at 16:41
  • At work my PC has two ethernet cables attached. Which one do you imagine is my "active" one? I would (if I cared) perhaps write some configuration file for my tools to let it HIDE the ones that I don't care about (say, VMWARE or Wifi, or whatever I don't care about). There are only "ones I care about". Let the user select from that list themself. – Warren P Oct 05 '16 at 18:32

0 Answers0