JSI Tip 7415. What non-domain computers on my network have IP addresses in my DHCP scope?

Jerold Schulman

November 5, 2003

2 Min Read
ITPro Today logo in a gray background | ITPro Today

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 offif {%4}
{} @echo Syntax: DHCPND DomainName Scope123 Scope4S Scope4E [NextScope123 NextScope4S NextScope4E .....]&goto :EOFsetlocalset domain=%1if exist %temp%DHCPND.tmp del /q %temp%DHCPND.tmpfor /f "Skip=1 Tokens=1" %%c in ('netdom query /domain:%domain% workstation') do if /i "%%c" NEQ "The" @echo %%c>>%temp%DHCPND.tmpfor /f "Skip=1 Tokens=1" %%c in ('netdom query /domain:%domain% server') do if /i "%%c" NEQ "The" @echo %%c>>%temp%DHCPND.tmpfor /f "Skip=1 Tokens=1" %%c in ('netdom query /domain:%domain% DC') do if /i "%%c" NEQ "The" @echo %%c>>%temp%DHCPND.tmp:moreif {%2}
{} goto Finishset 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)shiftshiftshiftgoto more:finishif exist %temp%DHCPND.tmp del /q %temp%DHCPND.tmpendlocalgoto :EOF:findset work=%stuff:[=%if "%work%" EQU "%stuff%" goto :EOFset stuff=%stuff: with 32 bytes of data:=%set OK=Yfor /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%



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like