Creating a variable for network card name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alkenerly
Posts: 1
Joined: 22 Nov 2013 12:33

Creating a variable for network card name

#1 Post by alkenerly » 22 Nov 2013 12:48

So, what im trying to do is set be able to set static ip's, dns's and wins. Im using netsh and wmic (to change the computer name according to my school's scheme) to do this. With netsh, i see i have to put in the name of the network connection like "Local Area Connection" for it to work. This is okay for the most part until we come across random computers that the network card name is something like "Ethernet" or even "Local Area Connection 4" and whatnot. So what I want to know is how I can set a variable to be the name of the active Network card. Here is the script I have now:

@echo off

echo "Please enter Static IP Address Information"

echo "What is your Room number? Only works at WCHS"
set /p Room=

echo "Enter IP Range"
set /p Range=

echo "Enter Last Digits Of IP"
set /p IP_Last=

echo "Doing all yall stuff for ya"

netsh interface ip set address "Local Area Connection" static 192.168.%Range%.%IP_Last% 255.255.255.0 192.168.%Range%.1

netsh interface ip set dns name="Local Area Connection" source=static addr=192.168.0.20
netsh interface ip add dns name="Local Area Connection" addr=192.168.0.21 index=2

netsh interface ip set wins name="Local Area Connection" source=static addr=192.168.0.20
netsh interface ip add wins name="Local Area Connection" addr=192.168.0.21 index=2

wmic.exe ComputerSystem Where Name="%ComputerName%" Rename Name="WCHS%Room%-%Range%%IP_Last%"

netsh int ip show config

pause


I'd like to be able to put of "netsh interface ip set address "%Network_Interface_Name%" static 192.168.%Range%.%IP_Last% 255.255.255.0 192.168.%Range%.1"

Is this possible? Any help would be greatly appreciated, also the commands to use have to already be on XP and windows 7. :mrgreen:

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Creating a variable for network card name

#2 Post by penpen » 23 Nov 2013 15:03

alkenerly wrote:So what I want to know is how I can set a variable to be the name of the active Network card
Do you mean the name displayed under "Description" when executing:

Code: Select all

ipconfig /all

If this may be what you need, then you can use this batch code:

Code: Select all

for /F "tokens=*" %%a in ('ipconfig /all ^| findstr "Description"') do set "description=%%a"
set "description=%description:*: =%

penpen

Post Reply