This will set your IP as a variable.
@echo off
ipconfig |FIND "IP" |FIND "." > %temp%.\$
for /F "tokens=2 delims=:" %%I in (%temp%.\$) do set IP=%%I
del %temp%.\$
set IP=%IP:~1%
echo IP=%IP%
Main Topics
Browse All TopicsI have a customer with a legacy batch file running that I need to modify very slightly. It set a dos variable called MyServername that contains \\Servername.
What I need to do is creat a new dos variable that is the IP address of that server. Its not so simple as editing the script and adding it in as this is on some 75 servers. Easiest way is if I can just automate the process of getting that \\Servername into the variable at runtime.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You can soon strip off the \\ using %servername:\=% and then PING the address and read the output to get the address:
@echo off
set myservername=\\servername
set ipaddress=
for /f "tokens=2 delims=[]" %%a in ('ping -n 1 -w 100 %servername:\=% ^| find "["') do set ipaddress=%%a
if [%ipaddress%]==[] echo Unable to get IP address
Steve
This didnt work for some reason. So.....
I cut n pasted each line into a dos box, with a valid servername, and ran each line in turn....
at the line.. for /f "tokens=2 delims=[]" %%a in ('ping -n 1 -w 100 %servername:\=% ^| find "["') do set ipaddress=%%a
I got %%a was unexpected at this time.
thoughts?>
Business Accounts
Answer for Membership
by: JeffPartonPosted on 2009-11-06 at 08:44:28ID: 25760717
Is the \\servername retrieved from the server that runs it dynamically, or does the bat file pull the %computername% from the script and set the Myservername variable from this? If you want to get an ip address with a logon batch you can use this:
IPCONFIG |FIND "IP" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%
echo %IP% >%temp%\ip.txt
echo The current IP address is "%IP%"
%IP% is the IP address of the server running the script.