How to locate IP address

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Is there an easy way to get your IP address?

I could do an ipconfig > outfile, and parse the outfile, but before I do
that, I thought I'd look for a designed approach.

Thanks in advance,

Dave
 
Is there an easy way to get your IP address?

I could do an ipconfig > outfile, and parse the outfile, but before I do
that, I thought I'd look for a designed approach.

Thanks in advance,

Dave

In a batch file:

set ip=NONE
for /F "Tokens=3 Delims=: " %%i in ('@ping -n 1 "%computername%"^|Find /i "Reply from"') do (
set IP=%%i
)
 
Dave said:
Is there an easy way to get your IP address?

I could do an ipconfig > outfile, and parse the outfile, but
before I do that, I thought I'd look for a designed approach.
Hi,

I think parsing the output from ipconfig is the easiest way:

--------------------8<----------------------
@echo off
setlocal enableextensions
ipconfig.exe >"%tmp%\ipaddr.txt"
for /F "tokens=2 delims=:" %%A in (
'findstr.exe "IP Address" "%tmp%\ipaddr.txt"') DO set ipaddr=%%A
del "%tmp%\ipaddr.txt"
set ipaddr=%ipaddr:~1%
echo %ipaddr%

--------------------8<----------------------
 
Back
Top