I've got a small nslookup .cmd, that gives me more output than needed. I already know the names of the machines I'm looking for, as well as the DNS name, the only Information I need is the machines address.
@echo off
set variable=1
:start
nslookup ***-%variable%.****** >> test.txt
set /a variable=variable+1
timeout /t 3
if %variable% LSS *** goto start
:next
This is what I get in my .txt file if the nslookup did find a machine:
Server: **********
Address: ...
Name: ****.****.****
Address: ...
But if it didnt find a machine i still get:
Server: **********
Address: ...
Could the output be manipulated that way, that it only writes to the .txt when it actually finds a machine and only takes the address part?
if you don't mind executing nslookup
twice per server (one time to check, if server exists, second to get the output):
nslookup ***-%variable%.****** 2>nul|findstr /b "Name:">nul && nslookup ***-%variable%.****** >> test.txt