Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NSLOOKUP in a batch file

5,573 views
Skip to first unread message

John Gray

unread,
Nov 21, 2012, 6:30:04 AM11/21/12
to
I haven't really used NSLOOKUP before, and am finding a lot of problems with trying to use it in a batch file to list all the DNS records for mydomain as they exist in the WebHost's name server.

Interactively, I can do
NSLOOKUP
SERVER <MyWebHost'sNameServer>
LS -D <mydomainname.com>
EXIT
but, unlike FTP, NSLOOKUP doesn't seem to support a command file.

And I can't get this to work as parameters on a command line, like
NSLOOKUP -type=any <mydomainname.com> <MyWebHost'sNameServer>

Can anyone assist, please?

Todd Vargo

unread,
Nov 21, 2012, 9:43:05 AM11/21/12
to
On 11/21/2012 6:30 AM, John Gray wrote:
> NSLOOKUP
> SERVER <MyWebHost'sNameServer>
> LS -D <mydomainname.com>
> EXIT

Place the commands in a file, lets say NSinput.txt.

SERVER MyWebHost'sNameServer
LS -D mydomainname.com
EXIT


Then redirect input from the file to NSLOOKUP.

NSLOOKUP < NSinput.text

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Frank Westlake

unread,
Nov 21, 2012, 9:47:41 AM11/21/12
to
On 2012-11-21 03:30, John Gray wrote:
> I haven't really used NSLOOKUP before...

Nor I.

> ... unlike FTP, NSLOOKUP doesn't seem to support a command file.
>
> And I can't get this to work as parameters on a command line, like
> NSLOOKUP -type=any <mydomainname.com> <MyWebHost'sNameServer>

It works with input redirected from a file:

(Echo SERVER MyWebHost'sNameServer & Echo LS -D
mydomainname.com)>inputScript

NSLOOKUP < inputScript

Also from a pipe:

TYPE inputScript | NSLOOKUP

Or:

(Echo SERVER MyWebHost'sNameServer & Echo LS -D mydomainname.com)|NSLOOKUP

I know that's more detail then you need but I'm writing for others also.

Frank

John Gray

unread,
Nov 21, 2012, 11:58:36 AM11/21/12
to
Thanks, both - obvious when you see it done!

Petr Laznovsky

unread,
Nov 21, 2012, 5:56:36 PM11/21/12
to
I am play with nslookup in batch files for some time with no satisfied
results (nslookup does not produce exit codes for example).

Suggest to you avoid to use it, and use Dig or Host instead..

http://members.shaw.ca/nicholas.fong/dig/

L.

Tom Del Rosso

unread,
Dec 3, 2012, 1:01:07 PM12/3/12
to
John Gray wrote:
>
> Thanks, both - obvious when you see it done!

To avoid getting stuck, I'd make sure there is an exit command at the end of
the file before using it.
First make another copy to avoid changing the original file.


copy /y NSinput.txt NSinputPlusExit.txt
echo EXIT>>NSinputPlusExit.txt
NSLOOKUP <NSinputPlusExit.txt
DEL NSinputPlusExit.txt


--

Reply in group, but if emailing add one more
zero, and remove the last word.


frank.w...@gmail.com

unread,
Dec 3, 2012, 3:05:39 PM12/3/12
to
From "Tom Del Rosso" :
>John Gray wrote:
>>
>> Thanks, both - obvious when you see it done!

>To avoid getting stuck, I'd make sure there is an exit
>command at the end of
>the file before using it.

I think in this case, and most cases, the termination of
the input stream causes the program to exit. But I only
tried it once with John's sample; does it not do the
same on your system?

Frank

John Gray

unread,
Dec 3, 2012, 3:32:22 PM12/3/12
to
I chose Frank's one-liner (the final example in his post), and it works flawlessly for me!

Tom Del Rosso

unread,
Dec 3, 2012, 10:05:48 PM12/3/12
to
OK, I never tried that. Most programs, like telnet and so on, do that? I
never gave them a chance to prove it.

ananth....@gmail.com

unread,
Jan 10, 2017, 7:22:22 PM1/10/17
to
REM @echo off
for /f "delims=\n" %%a in (server.txt) do nslookup %%a >> nslookup.txt
0 new messages