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");
精彩评论