Page 1 of 1
(SOLVED)-Nslookup and Non-authoritative answer
Posted: 03 Jan 2015 20:48
by Xboxer
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
Re: Nslookup and Non-authoritative answer
Posted: 03 Jan 2015 21:21
by Squashman
Code: Select all
nslookup yahoo.com 2>nul |find "Server"
or
Code: Select all
nslookup yahoo.com 2>&1 | find "Server"
Re: Nslookup and Non-authoritative answer
Posted: 04 Jan 2015 12:50
by Xboxer
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
Re: Nslookup and Non-authoritative answer
Posted: 04 Jan 2015 12:52
by Squashman
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.
Re: Nslookup and Non-authoritative answer
Posted: 04 Jan 2015 15:00
by Xboxer
Opps forgot bout the caret,
This for statement now supresses the popup message and outputs correctly.
Thanks for the hint, Xboxer
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