在 C# 中使用静态 IP 地址设置特定的 NIC [英] Setting a specific NIC with static IP Address in C#
问题描述
我正在尝试使用静态 IP 地址设置特定的 NIC.我参考了 this SO 帖子(由 Marc 回答)展示了如何做到这一点,除了它会设置所有已启用的 NIC.我试图只设置一个特定的.这就是我认为你会做的,但它不起作用,如果有人能指出我做错了什么,我想说的是?
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...
}
推荐答案
这是因为 (bool)managementObject["Caption"].ToString()
返回适配器的实际名称(即 Intel(R) 千兆网络连接)不是网络名称(即本地连接 2).
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# 中使用静态 IP 地址设置特定的 NIC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!