I have Windows 7 machines that get imaged, and after imaging I have to set the environment variable STATION to the last octet of the machine's IP address. How would I parse the IP address and grab the last octet to set the STATION variable?
This only sets the variable to the full ip address:
@echo off
for /f "tokens=1 delims=:" %%j in ('ping %computername% -4 -n 1 ^| findstr Reply') do (set localip=%%j)
SETX /m STATION "%localip:~11%"
do it with another
for:May I suggest:
(I used a different method to get the IP, because yours depends on local settings - for example on my computer I would have to search for
Antwortinstead ofReply. But the syntax is the same in all languages, so the IP is always enclosed by[and])