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:

Begin,the,csv
JSI001.JSIINC.ORG,\{F651A57B-7286-42BF-A0D4-06C386EC5B77\},192.168.0.1
JSI005,\{33CBD362-FDA7-4E37-835A-C6929633A956\},192.168.0.10
End,the,csv
The script, FixedIpNICs.bat, requires 1 parameter, the output file. FixedIpNICs.bat contains:
@echo off
if \{%1\} EQU \{\} goto syntax
setlocal
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%
endlocal
goto end
:syntax
@echo Syntax: FixedIpNICs outputfile
goto end
:computer
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=
:loop
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
:ipa
set IP=%1
if %ip% EQU "" goto end
set IP=%IP:"=%
if "%IP:~0,4%" EQU "key " goto end
if "%IP:~0,7%" EQU "0.0.0.0" goto end
if "%IP%" EQU "%pIP%" goto end
@echo %rp1%,%RegValue%,%IP%>>%outfile%
set pIP=%IP%
:end



Hide comments

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.
Publish