How to remove only the IP Addres from the IPCONFIG command in DOS
I have a simple question with an even simpler answer. When I run the IPCONFIG command from dos it displays the IP amongst other things. I would like to pipe (>) JUST THE IP TO A .txt FILE. I do not want the whole " Address. . . . . . . . . . . . : 123.123.123.123" line.
::This will perform the IPCONFIG command and send the output to c:\ip.txt
IPCONFIG > c:\ip.txt
Note that the following different display scenarios needs to be catered for as found in ip.txt:
IPv4 Address. . . . . . . . . . . : 192.168.1.103
IP Address. . . . . . . . . . . . : 192.168.1.103
IPv4 Address. . . . . . . . . . . : 1.1.1.1
IP Address. . . . . . . . . . . . : 1.1.1.1
If this can be performed with a simple vbscript that will also be acceptable. Please note however that "first prize" would be pure dos bat commands.
Microsoft DOSWindows OSProgramming
Last Comment
ReneGe
8/22/2022 - Mon
knightEknight
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find "IP Address"') do (
set _result=%%J
echo !_result! >> myIP.txt
)
knightEknight
change the last line to this and it will remove the leading space:
echo !_result:~1! >> c:\ip.txt
Steve Knight
Some other ways of mine here for you too if interested:
Do you need the IPv4 Address as well as the IP Address lines?
Also, do you want to exclude the 1.1.1.1 addresses?
Below is a simplified version of my previous post that does both of the above:
@echo off
for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find/v "1.1.1.1" ^| find "IPv4 Address"') do @echo %%~J >> c:\ip.txt
for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find/v "1.1.1.1" ^| find "IP Address"') do @echo %%~J >> c:\ip.txt
Rebel_no_1
ASKER
Simplified... :-)
I like that word!
I ran the last script knighteknight. It basically already works acceptably but I would like to not have the leading space... You guys are such big geeks, but DAMN, your'e smart! (I mean that in a very good way!)
setlocal enabledelayedexpansion
for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find "IP Address"') do (
set _result=%%J
echo !_result! >> myIP.txt
)