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.