我想为电脑中的每个网络接口设置IP。我使用从C++代码中调用的以下命令。
netsh interface ip set address "Local Area Connection" static ipaddr subnetmask gateway metric
因为netsh
需要适配器的名称,所以我使用GetAdaptersInfo
来获取所有适配器。问题是GetAdaptersInfo
将名称返回为GUID,而不是netsh
所要求的"本地连接4"。
我的问题是:
- 我可以根据MAC而不是"本地连接"来设置ip吗
- 如果(1)不能完成,那么如何将作为GUID的
GetAdaptersInfo->AdapterName
转换为"本地连接"
我发现了如何获得可以传递给netsh
的友好名称。正如这篇文章所说,我们需要使用GetAdaptersAddresses
,而不是GetAdaptersInfo
。