Writing IP address to file

17,069

Solution 1

ipconfig | find "IP Address" > out.txt

You still need to extract the IP Address from "IP Address.............: 0.0.0.0" and trim any whitespace.

Solution 2

Simplest i can think of:

ipconfig > file

Solution 3

Is this what you're looking for?

@echo on

for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IP Address"') do set ip=%%b

set ip=%ip:~1%

echo %ip%

Solution 4

For Windows 7 machines:

ipconfig | findstr /b /c:"   IPv4" > output.txt

There are three whitespace characters between the opening quotation mark and IPv4 since that line technically begins with whitespace. I am unaware of a way to strip that prior to the findstr command.

Remember that, even though it's technically regular expressions, the Windows command line doesn't parse them the same way as, say, C# or whatever. There's a list of the acceptable sequences/wildcards (marked for XP, but it worked for me in a Win7 environment) here.

Took me a little trial and error, but this gets you ONLY the lines for assigned IPv4 addresses, and not the "Autoconfigured" stuff that clutters the results of other findstr iterations.

Share:
17,069
Christian 'fuzi' Orgler
Author by

Christian 'fuzi' Orgler

Updated on June 04, 2022

Comments

  • Christian 'fuzi' Orgler
    Christian 'fuzi' Orgler almost 2 years

    Is there any simple command to write the ip-address into a file?

    I know how to write in a file, but is there a sysvar or something!?

  • Christian 'fuzi' Orgler
    Christian 'fuzi' Orgler over 13 years
    yeah, but do you know how to get ONLY the ip-address? hm
  • Vicky
    Vicky over 13 years
    Bear in mind also there may be more than one IP address, if you have more than one network adapter.
  • barti_ddu
    barti_ddu over 13 years
    @fuzi: you could do something like ipconfig | find "IPv4" > file and then for /f "tokens=2 delims=:" %i in (file) do echo %i >> ip.txt
  • Lightness Races in Orbit
    Lightness Races in Orbit over 12 years
    Which IP address? Which gateway?