Command only listing active NIC?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
emos
Posts: 2
Joined: 29 Jan 2018 15:23

Command only listing active NIC?

#1 Post by emos » 10 Apr 2019 11:34

Hi,

I'm trying to put to gather a script that search for a specific Network Adapter Name. But what ever i do only my Wireless card is the only adapter name i can get going.
I'm i using "find" incorrect?

Code: Select all

@echo off
for /f "skip=3 tokens=1,2,3* delims= " %%a in ('netsh interface show interface ^|find /v "Ethernet"') do  Set AdapterName=%%d
if %AdapterName%=="Ethernet" (GOTO BEGIN) Else (GOTO SELECT_NIC)
	
	
	
:%%a = Status
:%%b = Connection status
:%%c = Type?
:%%d = Interface name

:BEGIN
echo You made it

:SELECT_NIC
echo **ERROR**
echo Could not find adapter name
echo.
echo %AdapterName%
pause
Image

-Evan

Joe Caverly
Posts: 2
Joined: 11 Jul 2018 05:05

Re: Command only listing active NIC?

#2 Post by Joe Caverly » 11 Apr 2019 05:03

This is how I would approach the query;

Code: Select all

WMIC.EXE Path Win32_NetworkAdapter Get /FORMAT:CSV | findstr /c:"Ethernet"
For example; to find the D-Link Adapter on my system;

Code: Select all

WMIC.EXE Path Win32_NetworkAdapter Get /FORMAT:CSV | findstr /c:"D-Link DWA-525 Wireless N 150 Desktop Adapter(rev.A2)"
For more info and examples for WMIC.EXE, visit https://ss64.com/nt/wmic.html

WMIGen.exe will generate Batch code for menu selected WMI queries.

https://www.robvanderwoude.com/wmigen.php

Joe

jfl
Posts: 98
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Command only listing active NIC?

#3 Post by jfl » 11 Apr 2019 06:24

I have a script that does just that: ipcfg.bat, part of my System Tools Library

ipcfg.bat has lots of options. But the idea is to select only "interesting" network information.
By default, it outputs just the information for the active NICs, as you're trying to do.
Examples:

Code: Select all

C:\JFL\Temp>ipcfg -l
Ethernet 2
Ethernet 5
LAN
Local Area Connection* 5
Local Area Connection* 7
VirtualBox Host-Only Network
Wi-Fi

C:\JFL\Temp>ipcfg LAN
Connection-specific DNS Suffix  . : emea.hpqcorp.net
Link-local IPv6 Address . . . . . : fe80::4dc9:e55f:cc0a:950e%7
IPv4 Address. . . . . . . . . . . : 10.38.145.38
Subnet Mask . . . . . . . . . . . : 255.255.252.0
Default Gateway . . . . . . . . . : 10.38.144.1

C:\JFL\Temp>

Post Reply