put ip address in an environment variable

  • Thread starter Thread starter Marco Berizzi
  • Start date Start date
M

Marco Berizzi

Is there a way to put the current
ip address (taken from dhcp server)
in to an environment variable?

For example:

C:\>echo %ipaddress%
172.16.1.227
 
Marco Berizzi said:
Is there a way to put the current
ip address (taken from dhcp server)
in to an environment variable?

For example:

C:\>echo %ipaddress%
172.16.1.227

Try this:

@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find /i "ip address"') do
set IP=%%a
set IP=%IP: =%
 
Back
Top