Skip to main content

 none
Get MAC address of the pysical network interface card- not virtual interface RRS feed

  • Question

  • Hello,

    We need to get the MAC address of the physical network interface.

    Called GetAdaptersInterfaces() , which returns all interfaces on the PC.

    But could not isolate the physical interface card from the virtual network interface cards.

    Kindly let us know is there any other API or structure member which helps to identify whether the given interface is physical or virtual.

    Thanks in advance.

    Wednesday, June 24, 2015 7:01 AM

All replies

  • Ref: http://stackoverflow.com/questions/1567377/how-to-determine-mac-address-of-the-actual-physical-network-card-not-virtual

    This is my method: it uses the fact that physical card is connected to PCI interface

    ManagementObjectSearcher searcher = new ManagementObjectSearcher
        ("Select MACAddress,PNPDeviceID FROM Win32_NetworkAdapter WHERE MACAddress IS NOT NULL AND PNPDeviceID IS NOT NULL");
    ManagementObjectCollection mObject = searcher.Get();
    
    foreach (ManagementObject obj in mObject)
    {
        string pnp = obj["PNPDeviceID"].ToString();
        if (pnp.Contains("PCI\\"))
        {
            string mac = obj["MACAddress"].ToString();
            mac = mac.Replace(":", string.Empty);
            return mac;
        }
    }


    Best Regards,
    Please remember to mark the replies as answers if they help

    Thursday, June 25, 2015 12:24 PM
  • Thank you for your reply.

    can I get it with vC++ code?

    Kindly let us know.

    Thursday, June 25, 2015 12:34 PM