CMD/Batch get active interface name as variable

前端 未结 2 1813
猫巷女王i
猫巷女王i 2021-01-23 10:08

I\'m currently having a hard time figuring out how to get the active interface names as a variable output which can be later on used in the code. I\'ve been reading here a bit,

2条回答
  •  盖世英雄少女心
    2021-01-23 10:43

    to get the names of all interfaces that are connected:

    FOR /F "tokens=3,*" %%A IN ('netsh interface show interface^|find "Connected"') DO echo %%B
    

    Note: this is language dependent.

    For a language independent solution use wmic (which has it's own traps and oddities):

    for /f "tokens=2 delims==" %%a in ('wmic nic where (NetConnectionStatus^=2^) get name /value') do (
      for /f "delims=" %%b in ("%%a") do echo %%b
    )
    

    The inner for is to handle the ugly wmic line endings

提交回复
热议问题