Find Local IP in batch file

Posted on 2009-04-24
Medium Priority
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

Shift-3 earned 2000 total points
ID: 24226276
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

ID: 31574247
That works...thanks much!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

839 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