This is going to just be a quick post but hopefully thereā€™s enough detail to get you going.

I needed a way to display just the IP address of a computer within a batch file. I accomplished this by using a combination of FOR, ipconfig, and find:

FOR /F "delims=: tokens=2" %%a in ('ipconfig ^| find "IPv4"') do set _IPAddress=%%a
ECHO %_IPAddress%

The heart of the command is ipconfig. Youā€™re probably familiar with it, but if youā€™re not it displays a bunch of IP related information for the computer youā€™re on. This includes the IP address.

The next part is find. This only outputs the lines that have a string match. Iā€™m feeding it ā€œIPv4ā€ as Iā€™m using it in WinPE v3.1, which is Windows 7 based. In XP and older youā€™d have to change ā€œIPv4ā€ to ā€œIP Addressā€ or something like that.

The for statement simply pulls out the correct part of the string and stores it in a variable called _IPAddress. This can then be echoed anywhere else in the batch file.



Gregory Strike

Husband, father, IT dude & blogger wrapped up into one good looking package.