Differentiate VMware network adapter from physical network adapters -or- Detect Virtual Network Adaptor

后端 未结 3 850
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 15:28

I have to differentiate between the real addresses and the VM addresses using any Windows API. I\'m using GetAdaptersAddresses API to populate a list of IP addr

3条回答
  •  温柔的废话
    2020-12-24 15:33

    You can pass NetworkInterface in below method and it will return boolean to indicate that the NIC is Physical or not.

            private static bool IsPhysicalAdapter(NetworkInterface ni)
            {
               bool isPhysical = false;
    
               ManagementObjectSearcher searcher = new 
                                  ManagementObjectSearcher(@"root\CIMV2", 
                                  string.Format(@"SELECT * FROM  Win32_NetworkAdapter 
                                  WHERE GUID='{0}' AND NOT PNPDeviceID LIKE 'ROOT\\%'", 
                                  ni.Id));
    
               foreach (ManagementObject share in searcher.Get())
               {
                    isPhysical = 
                       Convert.ToBoolean(share.Properties["PhysicalAdapter"].Value);
                    break;
               }
    
               return isPhysical;
            }
    

提交回复
热议问题