how i get hostnames from domain using batch

Dell Poweredge 2600 server
January 19, 2011 at 10:29:15
Specs: Windows XP, core2dup/1GB
i have a DC and i want to get hostnames and ip of machines using domain

See More: how i get hostnames from domain using batch

Report •

January 19, 2011 at 12:19:51

but you could als0 do a reverse lookup through the DNS NSLOOKUP. Here is some code I wrote a long time ago...

@echo off

set OutputFile=c:\result.txt
set ListFile=c:\servers.txt

echo y|del %OutputFile%

for /f "tokens=1,2 delims= " %%a in (%ListFile%) do (
  call :Sub %%a %%b
  echo Checking %%a %%b)
notepad "%OutputFile%"
goto :eof

  ping %1 -n 1 > NUL
    set state=Off Line
    set name=%1
    set IP=
  ) else (
    set Name=%2
    set state=On Line
    call :RDNS %1
  echo %Name%,%state%   %IP%,%2 >> "%OutputFile%"
goto :eof

 for /f "tokens=1,2 delims= " %%A in ('nslookup %1') do (
  if "%%A"=="Name:" call :SetName %%B
  if "%%A"=="Address:" call :SetIP %%B
  if "%%A"=="Addresses:" call :SetIP %%B)
goto :eof

  set IP=%1
goto :eof
  set Name=%1
goto :eof

The Contents of Servers.txt looks like...

Will return the computer host name and if it is online in the log.

Or you can put in computer names along with assigned users like...

computer0001 JDoe
computer0002 MSmisth
svr1 DC
svr2 FileServer

and it will return the IP along user in the log.

To do what you want just modify this line...

echo %Name%,%state% %IP%,%2 >> "%OutputFile%"


echo %Name% >> "%OutputFile%"

Hope this helps.

Report •

January 19, 2011 at 12:54:52

Report •

January 20, 2011 at 11:50:28
thanx ace_omega,

in my domain there are 1500 machines are there. so, i looking script which run on server and i'll get result of whole machines.

Report •

Related Solutions

January 20, 2011 at 11:54:23
Well the code I gave you should work as long as you are using the same DNS for all computers. I use this same script on my network and it works great.

Report •

January 20, 2011 at 22:19:08
hi ace_omega,

i having 2 DNS servers, so this script giving blank result.
can you give me idea about what to change and where changes made in script.


Report •

Ask Question