(SOLVED)-Nslookup and Non-authoritative answer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Xboxer
Posts: 25
Joined: 27 Nov 2014 13:58

(SOLVED)-Nslookup and Non-authoritative answer

#1 Post by Xboxer » 03 Jan 2015 20:48

When using this below script with Nslookup it reads the host correctly but also outputs the message "Non-authoritative answer:" as well. Anyway to nul out this message?
Thanks for the help, Xboxer

Code: Select all

@Echo Off
Set "Domain=Yahoo.com."
IPConfig /Flushdns >Nul 2>&1

:: ISP HOST NAME
For /F "Usebackq Tokens=2" %%B In (`Nslookup %Domain% ^| Find "Server"`) Do Set HostName=%%B
Echo. %HostName%
Pause>Nul
Last edited by Xboxer on 04 Jan 2015 17:08, edited 1 time in total.

Squashman
Expert
Posts: 4206
Joined: 23 Dec 2011 13:59

Re: Nslookup and Non-authoritative answer

#2 Post by Squashman » 03 Jan 2015 21:21

Code: Select all

nslookup yahoo.com 2>nul |find "Server"

or

Code: Select all

nslookup yahoo.com 2>&1 | find "Server"

Xboxer
Posts: 25
Joined: 27 Nov 2014 13:58

Re: Nslookup and Non-authoritative answer

#3 Post by Xboxer » 04 Jan 2015 12:50

Thanks Squashman your commandline works but when I put it in my For /F statement it just flashes and does not work. :(

Code: Select all

For /F "Usebackq Tokens=2" %%B In (`nslookup yahoo.com 2>nul |find "Server"`) Do Set HostName=%%B
Echo. %HostName%
Pause>Nul

Squashman
Expert
Posts: 4206
Joined: 23 Dec 2011 13:59

Re: Nslookup and Non-authoritative answer

#4 Post by Squashman » 04 Jan 2015 12:52

I think if you look at your first set of code you will see what character is missing. You always need this character when using a pipe with the FOR /F command.

Xboxer
Posts: 25
Joined: 27 Nov 2014 13:58

Re: Nslookup and Non-authoritative answer

#5 Post by Xboxer » 04 Jan 2015 15:00

Opps forgot bout the caret, :roll: This for statement now supresses the popup message and outputs correctly.
Thanks for the hint, Xboxer :mrgreen:

Code: Select all

For /F "Tokens=2 Delims=:" %%B In ('Echo quit^|Nslookup^|Find "Server"') Do Set HostName=%%B


Must Run AS ADMIN..

Code: Select all

For /F "Usebackq Tokens=2" %%B In (`Nslookup Yahoo.Com 2^>Nul ^| Find "Server"`) Do Set HostName=%%B
Echo. %HostName%
Pause>Nul

Post Reply