Avatar of Rebel_no_1
Rebel_no_1
Flag for China asked on

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

Avatar of undefined
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:

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

Steve
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
knightEknight

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!)
SOLUTION
ReneGe

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
knightEknight

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
knightEknight

... that should capture both "IP Address" and "IPv4 Address" and filter out the 1.1.1.1 entries.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
knightEknight

... it will also capture "IPv6 Address" on newer machines (fyi).
Rebel_no_1

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

Glad I could help
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck