Skip navigation

JSI Tip 3461. How to I use Windows 2000 to build a CSV of fixed IP addresses on my DHCP enabled network?

In this script, I use NETDOM, from the Windows 2000 Support folder on the CD-ROM and the freeware REG from tip 0170.

The script must run on any Windows 2000 computer, but the 'PDC' might be faster. The domain can be Windows NT, Windows 2000, or Mixed.

The CSV file will be similar to:

The script, FixedIpNICs.bat, requires 1 parameter, the output file. FixedIpNICs.bat contains:
@echo off
if \{%1\} EQU \{\} goto syntax
set outfile=%1
if exist %outfile% del /q %outfile%
@echo Begin,the,csv>>%outfile%
REM Set registry path elements. 
set rp2=\machine\Software\Microsoft\Windows NT\CurrentVersion\Networkcardsset rp4=\ServiceName
set nic2=\machine\System\CurrentControlSet\Servicesset nic4=\Parameters\TcpIPset nic5E=EnableDHCP
set nic5IP=IPAddress
For /f "Skip=1 Tokens=1" %%i in ('netdom query /domain PDC') do call :computer "%%i" 
For /f "Skip=1 Tokens=1" %%i in ('netdom query /domain DC') do call :computer "%%i" 
For /f "Skip=1 Tokens=1" %%i in ('netdom query /domain SERVER') do call :computer "%%i" 
For /f "Skip=1 Tokens=1" %%i in ('netdom query /domain WORKSTATION') do call :computer "%%i" 
@echo End,the,csv>>%outfile%
goto end
@echo Syntax: FixedIpNICs outputfile
goto end
set rp1=%1
set rp1=%rp1:"=%
if "%rp1%" EQU "The" goto end
if "%rp1%" EQU "Directory" goto end
REM Set Key and notfound counters, initialize duplicate IP switch.
set /a rp3=0
set /a cnt=0
set pIP=
set /a cnt=%cnt% + 1
set /a rp3=%rp3% + 1
if %cnt% GTR 9 goto end
REM Retrieve nth NIC.
for /f "tokens=1*" %%j in ('REGfree -lv "\\%rp1%%rp2%%rp3%%rp4%"') do set RegValue=%%k
if "%RegValue:~0,4%" EQU "key " goto loop
set /a cnt=0
REM Retrieve NICs enabledDHCP TCP/IP settings.
for /f "tokens=1*" %%k in ('REGfree -lv "\\%rp1%%nic2%%RegValue%%nic4%%nic5E%"') do set DHCP=%%l
REM Bypassed DHCP enabled (and not found) NICs.
if "%DHCP%" EQU "1" goto loop
if "%DHCP:~0,4%" EQU "key " goto loop
REM Retrieve nth IP address (REG_MULTI_SZ data type).
for /f "tokens=1*" %%k in ('REGfree -lv "\\%rp1%%nic2%%RegValue%%nic4%%nic5IP%"') do call :ipa "%%l"
goto loop
set IP=%1
if %ip% EQU "" goto end
set IP=%IP:"=%
if "%IP:~0,4%" EQU "key " goto end
if "%IP:~0,7%" EQU "" goto end
if "%IP%" EQU "%pIP%" goto end
@echo %rp1%,%RegValue%,%IP%>>%outfile%
set pIP=%IP%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.