Windows:获取网卡的接口号

我有以下问题:我有一个具有相当dynamicnetworkingconfiguration的服务器,需要使用IF参数configuration它的路由:

route add ... mask ... ... if ? 

如果我知道该适配器的其他所有内容,是否有可靠的方法,手动和/或编程方式来获取该接口号?

您也可以在运行route print命令时看到该信息。 这是展示的第一件事。 该指数是第一列

 =========================================================================== Interface List 13... ......Bluetooth Device (Personal Area Network) 10... ......Intel(R) 82566MM Gigabit Network Connection 11... ......Intel(R) Wireless WiFi Link 4965AG 17... ......VMware Virtual Ethernet Adapter for VMnet1 18. . ......VMware Virtual Ethernet Adapter for VMnet8 

既然你知道关于适配器的其他一切,而且你正在使用Server 2008,你可以(也应该)使用接口名称添加netsh的路由 :

 netsh int ipv4 add route <remote netid>/<remote netmask> <interface name> <next hop> 

路由命令的使用在2008+以上通常被弃用。

以下命令显示接口列表:

netsh int ipv4 show interfaces

您可以使用PowerShell:

 Get-WMIObject Win32_networkadapter | Select-Object Name, AdapterType, InterfaceIndex | Format-List