Setting a specific NIC with static IP Address in C

2019-08-22 04:08发布

问题:

I'm trying to set a specific NIC with a static IP Address. I was referencing this SO post (answered by Marc) which show's how to do so except it will set all NIC's which are Enabled. I'm trying to only set a specific one. This is what I thought you'd do it but it doesn't work and I'm wording if anyone can point out what I'm doing wrong?

foreach (var managementObject in networkConfigs.Cast<ManagementObject>().Where(managementObject => (bool)managementObject["Caption"].ToString().Contains("Local Area Connection 2")))
    {
    .. the rest of the code is the same...
    }

回答1:

It's because (bool)managementObject["Caption"].ToString() returns the actual name of the adapter(i.e. Intel(R) Gigabit Network Connection) not the network name (i.e. Local Area Connection 2).



标签: c# .net wmi