Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8976117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:03:04+00:00 2026-06-15T19:03:04+00:00

I want to create a batch file that writes the local IP address on

  • 0

I want to create a batch file that writes the local IP address on a txt file. When i run a batch file with this code (file path is wrong but that’s not the problem):

ipconfig | find "IP Address" > \File.txt

I get the whole windows IP configuration (I changed some numbers and stuff with xxx to not show all info)

    IP Address. . . . . . . . . . . . : 100.100.100.223

    IP Address. . . . . . . . . . . . : 192.xxx.xxx.xxx

I want to write to a file only 100.100.100.223.

I’m new to batch files and i really searched a lot and I’m really confused. (maybe i’m searching with wrong keywords).

Forgot to tell I’m using Windows XP (Because some of the answers doesn’t work on XP).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:03:06+00:00Added an answer on June 15, 2026 at 7:03 pm

    Read the just written file’s first line into a variable using the SET /P command, then overwrite the file with that line using ECHO:

    ipconfig | find "IP Address" > \File.txt
    < \File.txt SET /P first_ip=
    ECHO %first_ip%> \File.txt
    

    UPDATE (in answer to comments):

    To extract just the IP address, you could use a FOR /F loop like this:

    ipconfig | find "IP Address" > \File.txt
    < \File.txt SET /P first_ip=
    FOR /F "delims=: tokens=2" %%I IN ("%first_ip%") DO (
      ECHO %%I> \File.txt
    )
    

    A FOR /F loop allows you to process text (a file or a string literal) line by line, splitting each line into fields (or tokens) based on the specified delimiter(s). You can read more about this command in the built-in help (FOR /?). I’ll only add that in this case the processed piece is a string literal (the value of first_ip), the delimiter is set to :, and the loop variable (%%I) receives the 2nd token, which is an IP address.

    Note that the space between : and the IP is preserved, i.e. it becomes part of the token ( 100.100.100.223) and, therefore, gets written to the file too. If you aren’t very happy about it, you could use a subroutine to get rid of the space, like this:

    ipconfig | find "IP Address" > \File.txt
    < \File.txt SET /P first_ip=
    FOR /F "delims=: tokens=2" %%I IN ("%first_ip%") DO (
      CALL :MyEcho %%I
    )
    :: the following command is there merely to
    :: avoid running (into) the subroutine again
    GOTO :EOF
    
    :MyEcho
    ECHO %1> \File.txt
    

    When the subroutine is called (CALL :MyEcho %%I), the argument is passed along with the leading space. But when processing the subroutine’s command line, that space is no longer seen as part of the value, because the argument is not quoted and so the parser sees merely an argument separated from the name with two spaces. Thus the %1 in the subroutine evaluates to the address without the leading space.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a batch file that moves all the files in this
I want to create a simple batch file that would perform some Visual Studio
i want to create a batch file that executes command in it every 1
I want to create a batch file, batch.bat , that accepts 2 mandatory arguments:
I want to create a batch file that deletes all TFS workspaces of a
I want to create a batch file that builds several Visual Studio 2010 projects.
I want to create a batch file that helps multiple users install numpy on
I want to create a batch file that will sort the files(based on created
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want to build .NET solution using batch file. I am aware that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.