Excuse me ...
Hello everyone,
I use the function "for" below to get the IP of the machine, but I need to change the last set of digits. I know the second column does this, but sometimes the ip can have 1,2 or 3 digits and how this function, it does not work.
ex:
192.168.1.1 -> must return 192.168.1.
192.168.1.12 -> must return 192.168.1.
192.168.1.123 -> must return 192.168.1.
192.168.1.1 -> preciso que retorne 192.168.1.
192.168.1.12 -> preciso que retorne 192.168.1.
192.168.1.123 -> preciso que retorne 192.168.1.
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IPv4."') do for %%b in (%%a) do set ip=%%b
if /i %ip% NEQ 1 set ip=%ip:~0,-2%
Thank you.
Pick up only part of the IP
Moderator: DosItHelp
Pick up only part of the IP
Last edited by AdilsonD on 08 Aug 2014 12:17, edited 1 time in total.
Re: Pegar apenas parte do IP
We mostly use the English Language to communicate on the forums. If you translate your question into English you may get a quicker response.
Re: Pegar apenas parte do IP
I think this is what you want to do.
Code: Select all
@echo off
for /f "tokens=2 delims=:" %%G in ('ipconfig ^| find "IPv4"') do (
for /F "tokens=1-4 delims=. " %%H in ("%%G") do (
set octet1=%%H
set octet2=%%I
set octet3=%%J
set octet4=%%K
)
)
echo %octet1%.%octet2%.%octet3%.%octet4%
pause
Re: Pegar apenas parte do IP
It worked perfectly. Thank you.
Re: Pick up only part of the IP
Code: Select all
@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig^| find "IPv4"') do set ip=%%a
set ip=%ip: =%
:#
echo %ip%| findstr \.[0-9][0-9][0-9]*$>nul&& (set ip=%ip:~,-1%& goto:#)
set ip
pause>nul
exit /b