Last number in IP Address

Joined
May 24, 2013
Messages
1
Reaction score
0
I'm after a DOS BAT file which wills store into varables the last numbers of a PC's IP Address. EG I want to store in varables 10 from 192.168.103.10.

I have...
for /f "delims=: tokens=2" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do (set tempip=%%a)
set tempip=%tempip: =%
echo %tempip%
pause

Just can find out how to store that last part of the IP Address (ie 10).
 

Ian

Administrator
Joined
Feb 23, 2002
Messages
19,873
Reaction score
1,499
Hi Jason, welcome to the forums!

I'm really rusty with BAT programming, but this may work?

for /f "delims=: tokens=2" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do (set tempip=%%a)
set tempip=%tempip: =%
for /f "delims=. tokens=4" %%g in ("%tempip%") do echo %%g
pause
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top