Link to home
Start Free TrialLog in
Avatar of Rebel_no_1
Rebel_no_1Flag 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.
Avatar of knightEknight
knightEknight
Flag of United States of America image

@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
Some other ways of mine here for you too if interested:

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

Steve
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

Avatar of 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
Avatar of ReneGe
ReneGe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... 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).
It works 100%! Thanks Allot for the help Knighte and ReneGe. It's really appreciated!
Glad I could help