Using NETDOM.EXE from the Support Tools folder of your Server Operating System CD-ROM, I have scripted DHCPND.bat to determine what non-domain computers on your network have IP addresses that are in the scope(s) of your domain's DHCP server.
The syntax for using DHCPND.bat is:
DHCPND DomainName Scope123 Scope4S Scope4E \[NextScope123 NextScope4S NextScope4E .....\]
where:
DomainName is the your NetBIOS or fully qualified domain name. Scope123 is the first 3 octets of a scope, like 192.168.0. Scope4S is the lowest value of the fourth octet that you want checked. Scope4E is the highest value of the fourth octet that you want checked. NextScope123 and NextScope4S and NextScope4E are optional addition scopes. There is no limit to the number of optional parameters.
Examples:
dhcp jsiinc 192.168.0 1 9 192.168.0 50 79 This is one scope, but I excluded 192.168.0.10 - 192.168.0.49 and addresses greater than 192.168.0.79. dhcp jsiinc.com 123.10.1 0 254 123.11.0 0 254 This is two full scopes.NOTE: DHCPND.bat displays its' output on the console.
NOTE: Ping is used to locate the computers. If a computer is powered off, it will NOT be found. If your scope contains unused addresses, Ping has to time out, increasing the run time.
DHCPND.bat contains:
@echo off if \{%4\}\{\} @echo Syntax: DHCPND DomainName Scope123 Scope4S Scope4E \[NextScope123 NextScope4S NextScope4E .....\]&goto :EOF setlocal set domain=%1 if exist %temp%\DHCPND.tmp del /q %temp%\DHCPND.tmp for /f "Skip=1 Tokens=1" %%c in ('netdom query /domain:%domain% workstation') do if /i "%%c" NEQ "The" @echo %%c>>%temp%\DHCPND.tmp for /f "Skip=1 Tokens=1" %%c in ('netdom query /domain:%domain% server') do if /i "%%c" NEQ "The" @echo %%c>>%temp%\DHCPND.tmp for /f "Skip=1 Tokens=1" %%c in ('netdom query /domain:%domain% DC') do if /i "%%c" NEQ "The" @echo %%c>>%temp%\DHCPND.tmp :more if \{%2\}
\{\} goto Finish set oct123=%2# set oct123=%oct123:.#=% set oct123=%oct123:#=% for /l %%i in (%3,1,%4) do ( for /f "Tokens=1,2* Delims=. " %%p in ('ping -a -n 1 %oct123%.%%i') do if "%%p" EQU "Pinging" set computer=%%q&set stuff=%%r&call :find ) shift shift shift goto more :finish if exist %temp%\DHCPND.tmp del /q %temp%\DHCPND.tmp endlocal goto :EOF :find set work=%stuff:\[=% if "%work%" EQU "%stuff%" goto :EOF set stuff=%stuff: with 32 bytes of data:=% set OK=Y for /f "Tokens=*" %%s in ('findstr /i /l /c:"%computer%" %temp%\DHCPND.tmp') do set OK=%computer%.%stuff% If "%OK%" NEQ "Y" goto :EOF @echo %computer%.%stuff%
0 comments
Hide comments