Find Local IP in batch file

Posted on 2009-04-24
Last Modified: 2012-05-06
This is the only section of the script that doesn't work.  It does pull the IP, but it outputs the IP with a leading space which kills the rest of my script.

When it needs to be

What am I doing wrong here?  The rest of my script works well.
::discover the local IP


for /f "tokens=2* delims=:" %%a in ('ipconfig ^| find "IP Address"') do set LOCALIP=%%a

echo %localip%

Open in new window

Question by:slayer199
    LVL 38

    Accepted Solution

    You can get rid of the space, either by using a substring to chop off the first character, e.g.
    set localip=%localip:~1%

    or by using substitution to remove all spaces from the variable, e.g.
    set localip=%localip: =%

    Author Closing Comment

    That works...thanks much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now