1

I am looking for a cmd command to return if the currently connected NIC is using a static or DHCP address. DHCP: YES or NO is acceptable.

I think ipconfig might be an option, but I need a way to sort out the DHCP field as well as make sure the field I am pulling is from the correct adapter.

I found this code which will pull out the IP Address, But I have not be able to adjust the code to pull the DHCP status.

for /f "delims=" %a in ('ipconfig ^| findstr [0-9].\.') do @echo %a | findstr "Address"

findstr of IP address

I tried

for /f "delims=" %a in ('ipconfig ^| findstr [0-9].\.') do @echo %a | findstr "DHCP Enabled"

and

for /f "delims=" %a in ('ipconfig ^| findstr [0-9].\.') do @echo %a | findstr "DHCP"

but they return nothing. I think im on the right track, I'm just not sure.

DHCP enabled in one place, but not in another

user3585839
  • 1,459
  • 3
  • 12
  • 18
  • `for /F "delims=" %I in ('ipconfig /all ^| findstr /R /C:"^ *IPv4 Address" /C:"^ *DHCP Enabled"') do @echo(%I`. You are first filtering lines containing `Address`, which do no longer include the `DHCP Enabled` lines... – aschipfl Mar 23 '17 at 16:01

1 Answers1

1
for /f "tokens=2 delims=:" %a in ('ipconfig /all ^|find "DHCP Enabled"') do echo DHCP:%a

Note: dependent on locale (language)
Note: will give you a line for every adapter (without telling you, which adapter)

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Is there a way to make this only show the connected adapter? I need to switch over ~500 computers to a new SSID, but I need to change the IP address if it is static to be within the new range. – user3585839 Mar 27 '17 at 14:35