I am developing window application in C#. I am using the following code to generate the MAC address. I want to generate unique MAC address. I want the MAC address of the primary Lan Card. For this scenario I am using the following code.
private void Form1_Load(object sender, EventArgs e)
{
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;
labelMACAddress.Text = mac;
}
}
}
I am not too much aware about the hardware devices or how to do programming for hardware configuration. In the above scenario I want the MAC address of the primary Lan Card in such a way that if I will use the other USB devices (the virtual card) to connect to the internet then my code must always generate the MAC address of the primary Lan Card. So I am using the above code. Now, I want to know that is the above code right for the above scenario ? Is the condition if (pnp.Contains("PCI\\"))
right for generating the MAC address for the primary Lan Card. Is in the above case tell me whether only primary lan card is connected to PCI interface or there are some other network cards also which are connected to the PCI Interface ?