How to set IP information as variables?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mrrhtuner
Posts: 10
Joined: 09 Jan 2012 14:02

How to set IP information as variables?

#1 Post by mrrhtuner » 27 Sep 2012 13:38

Hello everybody, I am working on a batch file that I'd like to use at work. I'm in the early stage of building this batch file, which will allow me to send to a end user and upon running it, the program will ask them:

If they need a static addres or dynamic

and if it is static, it will ask for a club number and based on the club number it will assign the IP address, SubNet/GW/DNS to the end user's laptop.


is there an easy way to create such variable for each club? Obviously the GW/IP changes at each club location so I'd like to figure out a way of setting a variable, such as: club 5 = IP x.x.x.x and GW x.x.x.x

Any suggestions/tips? thank you!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to set IP information as variables?

#2 Post by foxidrive » 27 Sep 2012 22:37

If I understand you: You can have a plain text file with a format of "name, IP address, GW address EG:

club5,100.100.100.100,200.200.200.200
club9,102.102.102.102,201.201.201.201


and read it in a for next loop:

Code: Select all

:loop
set var=
set /p "var=Enter club name: "
if not defined var goto :loop
for /f "tokens=1,2,3 delims=," %%a  in ('find /i "%var%" <infofile.txt ') do echo club %var% IP is %%b and GW is %%c

Post Reply