IP address as a variable on Windows 7?

November 22, 2010 at 22:21:45
Specs: Windows 7, Q8200
I need some way of getting the IP address of a computer as a variable in a batch file. This doesn't work (this code was posted on this forum and I don't remember the posters name(sorry)):

@echo off
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%"
pause

But all this yields is:
"FIND: IP: No such file or directory"
"The current IP address is "~1""
"Press any key to continue . . ."

Does anyone have a way that works on Windows XP, Vista and 7?


See More: IP address as a variable on Windows 7?

Report •


#1
November 23, 2010 at 00:23:11
Put computer name where I have localhost.

==========================================

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=2 delims=[]" %%a in ('ping -n 1 localhost') do (
set IP=%%a
)
echo.!IP!


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 23, 2010 at 00:28:15
or this

=========================================

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IP"') do (
set IP=%%a
)
set IP=!IP:~1!
echo.!IP!


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions


Ask Question