Pick up only part of the IP
Posted: 08 Aug 2014 11:55
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.
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.