如何设置IP到网络接口



我想为电脑中的每个网络接口设置IP。我使用从C++代码中调用的以下命令。

netsh interface ip set address "Local Area Connection" static ipaddr subnetmask gateway metric

因为netsh需要适配器的名称,所以我使用GetAdaptersInfo来获取所有适配器。问题是GetAdaptersInfo将名称返回为GUID,而不是netsh所要求的"本地连接4"。

我的问题是:

  1. 我可以根据MAC而不是"本地连接"来设置ip吗
  2. 如果(1)不能完成,那么如何将作为GUID的GetAdaptersInfo->AdapterName转换为"本地连接"

我发现了如何获得可以传递给netsh的友好名称。正如这篇文章所说,我们需要使用GetAdaptersAddresses,而不是GetAdaptersInfo

最新更新