patrick-it
Goto Top

Netzwerkkarte Variable zuweisen

Hallo liebes Forum

Ich versuche nun schon seit einigen Tagen in Batch die Netzwerkkarten automatisch mit einer automatisch zugewiesenen Variable auszugeben, damit ich nicht den ganzen Namen eingeben muss. Das ganze habe ich mir etwa folgendermassen vorgestellt:

Die Netzwerkkarten werden gescannt und ihnen wird eine Variable mit z.B. 1 und der Nächsten dann 2 zugewiesen. dann kann man die Karte mit der Zahl 1 auswählen.
In Batch stelle ich mir es etwa so vor

Variable...................................................Netzwerkkartenname
1...............................................................Netzwerkkarte-x
2...............................................................Netzwerkkarte-y
3...............................................................Netzwerkkarte-z

Ich hoffe auf eine hilfreiche Antwort

-Patrick

Content-Key: 272220

Url: https://administrator.de/contentid/272220

Printed on: April 19, 2024 at 18:04 o'clock

Mitglied: 114757
Solution 114757 May 18, 2015 updated at 10:07:30 (UTC)
Goto Top
@echo off & setlocal enabledelayedexpansion
set /a cnt=1
for /f "tokens=2 delims==" %%a in ('wmic nic where ^(NetEnabled ^= True^) get Description /format:list ^| findstr "Description"') DO @(  
	set "nic!cnt!=%%a"  
	echo [!cnt!] %%a
	set /a cnt+=1
)
echo.
set /p num=Bitte die Karte waehlen:
echo Sie haben folgende Auswahl getroffen: !nic%num%!
Gruß jodel32
Member: Patrick-IT
Patrick-IT May 18, 2015 at 10:18:11 (UTC)
Goto Top
Danke jodel32

Eine Sache wäre da noch: Anstatt der Netzwerkkarte müsste ich den Interface Namen der Netzwerkkarte genau so angezeigt bekommen, zum Beispiel Local Area Network, damit ich mit netsh Arbeiten kann.

Gruss Patrick-IT
Mitglied: 114757
Solution 114757 May 18, 2015 updated at 10:23:28 (UTC)
Goto Top
Einfach stattdessen die NetConnectionID nehmen.
@echo off & setlocal enabledelayedexpansion
set /a cnt=1
for /f "tokens=2 delims==" %%a in ('wmic nic where ^(NetEnabled ^= True^) get NetConnectionID /format:list ^| findstr "NetConnectionID"') DO @(  
	set "nic!cnt!=%%a"  
	echo [!cnt!] %%a
	set /a cnt+=1
)
echo.
set /p num=Bitte die Verbindung waehlen:
echo Sie haben folgende Auswahl getroffen: !nic%num%!