开发者

How do I enumerate network adapters on a Hyper-V guest using WMI?

开发者 https://www.devze.com 2022-12-21 01:32 出处:网络
I\'ve got a Hyper-V host, with several guests, each with one or more network adapters. How do I enumerate the network adapters on those gue开发者_JS百科sts?

I've got a Hyper-V host, with several guests, each with one or more network adapters. How do I enumerate the network adapters on those gue开发者_JS百科sts?

Specifically, I'm looking for a particular guest, given a MAC address.

I'm using C# and System.Management.


I'll leave out some of the details:

  • Connect to Hyper-V on the host.
  • Enumerate the machines (SELECT * FROM Msvm_ComputerSystem).
  • For each machine, find the associated Msvm_SyntheticEthernetPort objects.
var ports = computerSystem.GetRelated("Msvm_SyntheticEthernetPort");
foreach (ManagementObject port in ports)
{
  • Get hold of the settings:
    var portSettings = port.GetRelated("Msvm_SyntheticEthernetPortSettingData");
    foreach (ManagmentObject portSetting in portSettings)
    {
  • Look for the configured MAC address:
        string macAddress = (string)portSetting .GetPropertyValue("Address");
0

精彩评论

暂无评论...
验证码 换一张
取 消