1

I am trying to extract the DHCP status and IP address from ipconfig /all and set it to a variable.

Can this be done?

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
Kwehmann
  • 21
  • 4

2 Answers2

2

It's easier using Netsh try this:

@echo off
setlocal enabledelayedexpansion

for /f "skip=2 tokens=* delims=" %%a in (
  'netsh interface ipv4 show config name^="local area connection"'
) do (
    set /a cnt+=1 
    if !cnt! equ 3 (
      goto :break
    ) ELSE (echo(%%a
  )
)  
:break

Change local area connecton to suit your environment.

Matt Williamson
  • 6,947
  • 1
  • 23
  • 36
0

Well - I'm doing this with grep.

I don't know exactly what you need, but for example if you need the DHCP-server:

for /F %%i in ('ipconfig -all ^| grep "DHCP Server" ^| grep -Eo '[0-9][0-9.]+'') do set DHCPServer=%%i

and for the local IP:

for /F %%j in ('ipconfig ^| grep "IPv4" ^| grep -Eo '[0-9][0-9.]+'') do set IpAdress=%%j

Both commands are working inside a batch file.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
mr netlord
  • 195
  • 1
  • 3
  • 11