Long time reading. First time poster.
I have a Windows machine with many NICs, and rather than the normal ipconfig, I want a simple way of showing the IP address(es) of just the adapter(s) that is(are) connected.
Looking at previous questions on this forum, I think the following command would work, if somebody please point me on how to pass the double quotes to the last variable:
for /f "tokens=2 delims==" %F in ('wmic nic where "NetConnectionStatus=2 and AdapterTypeId=0" get NetConnectionID /format:list') do netsh interface ip show config name="%F%"
Note: in a batch file, it would be %%F instead of %F.
I've tried several escaping methods, but it seems the part after the %F is not recognized.
The expected output would it be something like (please ignore the Spanish, the IP address is the information of interest):
netsh interface ipv4 show config name="Wi-Fi"
Configuración para la interfaz "Wi-Fi"
DHCP habilitado: Sí
Dirección IP: 192.168.1.12
If you wanted to continue to use WMIC with NetSh, then the following may suit your purposes:
Directly in cmd.exe:
In a batch file:
Please note that this assumes that the string
IPis unique in the output for the target line, (it clearly is for both English and your language, but that is not a guarantee).For the reason given in the footnote for the above code examples, my preference would be to just use WMIC, like this:
Directly in cmd.exe:
In a batch file:
I suppose you could also get the help of PowerShell too…
Directly in cmd.exe:
As a batch file:
Please note the above examples are untested.