如何使用 WMIC NICCONFIG 批量选择基本以太网接口 ipo 虚拟以太网或其他接口?

如何使用 WMIC NICCONFIG 批量选择基本以太网接口 ipo 虚拟以太网或其他接口?

我有一个小子程序,提供名为“CARTE”的网络接口的描述和索引,因此当使用 %CARTE%=wireless 调用时,它会返回无线接口的正确索引 (2),但是当使用 %CARTE%=Ethernet 调用时,它会返回 Virtualbox 虚拟以太网接口的索引 (12),而不是以太网主板 (1)。

命令行显示:

wmic nicconfig get description,index /format:csv

Node,Description,Index
P50-CLAUDE,Microsoft Kernel Debug Network Adapter,0
P50-CLAUDE,Intel(R) Ethernet Connection (2) I219-LM,1
P50-CLAUDE,Intel(R) Dual Band Wireless-AC 8260,2
P50-CLAUDE,Microsoft Wi-Fi Direct Virtual Adapter,3
P50-CLAUDE,Microsoft Wi-Fi Direct Virtual Adapter,4
P50-CLAUDE,WAN Miniport (SSTP),5
P50-CLAUDE,WAN Miniport (IKEv2),6
P50-CLAUDE,WAN Miniport (L2TP),7
P50-CLAUDE,WAN Miniport (PPTP),8
P50-CLAUDE,WAN Miniport (PPPOE),9
P50-CLAUDE,WAN Miniport (IP),10
P50-CLAUDE,WAN Miniport (IPv6),11
P50-CLAUDE,WAN Miniport (Network Monitor),12
P50-CLAUDE,Bluetooth Device (Personal Area Network),13
P50-CLAUDE,Windscribe VPN,14
P50-CLAUDE,VirtualBox Host-Only Ethernet Adapter,15
P50-CLAUDE,RAS Async Adapter,16
P50-CLAUDE,Windscribe Windtun420,17

我如何将索引搜索限制为值 3?我尝试过类似“&& where %idx% LWR”或“&& where %idx% < '3'”的方法,但没有成功……有人能帮我解释一下我的错误吗?谢谢!

附言:我知道批处理和 WMIC 已被弃用,但这只是为了进行小而快速的硬件测试......

:GETNIC
rem -------------------------------------------
rem returns DESCRIP and IDX of interface CARTE
set nicline="wmic nicconfig where "description like '%%%CARTE%%%'" get description^,index^ /format:csv^"
for /F "tokens=2-3 delims=," %%a in ('%nicline%') Do (
    set "DESCR=%%~a" & set "IDX=%%~b"
)
exit /b %DESCR%, %IDX%

答案1

我如何才能将索引搜索限制为值 3?

  • 我不确定我是否 100% 理解了您的问题,
    但据我理解,我建议您限制索引的输出:
  • index<=3  
    index>=1 and index<=3
    
  • 或者使用| findstr /End,”+[Rex-Range]
    for /F ... ('%nicline% ^| findstr /e ^,[0-3]')do ... 
    for /f tokens^=2*^delims^=^, %i in ('wmic nicconfig get  description^,index /format:csv ^| findstr /e ^,[0-3]
          ')do echo/ %%i,%%j
    
wmic nicconfig where "index<=3" get description /format:csv
wmic nicconfig where "index>=1 and index<=3" get description,index /format:csv

相关内容