CMD/Batch get active interface name as variable -
i'm having hard time figuring out how active interface names variable output can later on used in code. i've been reading here bit, how use cmd output variable, need specific names active.
my current code:
@echo off netsh interface show interface /f "tokens=* usebackq" %%f in (`netsh interface show interface`) ( set var=%%f ) echo %var% pause which displays image:
can see due
netsh interface show interface
, 2 connected interfaces , 2 non connected shown. however, how f.ex. ethernet 2 , wifi variable %%v ?
to names of interfaces connected:
for /f "tokens=3,*" %%a in ('netsh interface show interface^|find "connected"') echo %%b note: language dependent.
for language independent solution use wmic (which has it's own traps , oddities):
for /f "tokens=2 delims==" %%a in ('wmic nic (netconnectionstatus^=2^) name /value') ( /f "delims=" %%b in ("%%a") echo %%b ) the inner for handle ugly wmic line endings
Comments
Post a Comment