How to remove only the IP Addres from the IPCONFIG command in DOS

Rebel_no_1
Rebel_no_1 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find "IP Address"') do (
  set _result=%%J
  echo !_result! >> myIP.txt
)
change the last line to this and it will remove the leading space:

  echo !_result:~1! >> c:\ip.txt

Commented:
Some other ways of mine here for you too if interested:

http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet

Steve
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

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

Author

Commented:
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!)
Commented:
@Rebel

Here's what you hopefully asked for.

Please do not give a first prize. But rather split with contributors that freely gave their time to help you.

Cheers,
Rene

@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Output=c:\ip.txt
IF EXIST %Output% DEL %Output%

FOR /F "tokens=2 delims=:" %%A IN ('ipconfig ^| FINDSTR -i IPV4') DO (
	SET IP=%%A
	ECHO !IP: =!
	ECHO !IP: =!>>%Output%
)

PAUSE

Open in new window

One line script:

for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find/v "1.1.1.1" ^| findstr "IP..*Address"') do @echo %%~J >c:\ip.txt


but to remove the space I'll have to defer back to a slightly modified version of my original script.  It is necessary to set a variable first and then remove the space from it:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,* delims=:" %%I in ('ipconfig ^| find/v "1.1.1.1" ^| findstr "IP..*Address"') do (
  set _result=%%J
  echo !_result:~1! >> c:\ip.txt
)
... that should capture both "IP Address" and "IPv4 Address" and filter out the 1.1.1.1 entries.
... it will also capture "IPv6 Address" on newer machines (fyi).

Author

Commented:
It works 100%! Thanks Allot for the help Knighte and ReneGe. It's really appreciated!

Commented:
Glad I could help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial