[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4889
  • Last Modified:

How to export cmd.exe output to a .txt file when using the command nslookup

I want to make a list of all computers found in my corp. domain by using nslookup.
Nslookup allows me to list all computers within the domain using a DNS server of
my choice. ping 192.168.0.1 > C:\output.txt works, but inside nslookup i cannot
reproduce the results.
0
Neuroner
Asked:
Neuroner
  • 6
  • 4
1 Solution
 
Glen KnightCommented:
nslookup item_you_want_to_lookup > c:\output.txt
0
 
NeuronerAuthor Commented:
I need to specify a dns server first, my standard DNS server can't see everyone.
This is what I have dont before now:
nslookup
server 10.10.10.10
ls domain.net
(my output here)

Can we put that into the one line as well?
0
 
Steve KnightIT ConsultancyCommented:
Within nslookup you can do:

nslookup
> ls yourdomain.local
exit

You can do

nslookup
> ls yourdoman.local > file.txt
exit

to get results so you could do that from a batch file with:

@echo off
echo ls yourdomain.local >tempfile.txt
echo exit >>tempfile.txt
nslookup < tempfile.txt > output.txt
notepad output.txt

and it will (depending upon your settings) allow listing of all domain records.

Steve
0
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 
NeuronerAuthor Commented:
I now tried setting my standard DNS to be the DNS I need to do this command.
That removes the server 10.10.10.10 line of the code. I then used the syntax
demazter gave me, but got an error message. I have to start nslookup before
I can use the ls command, or else I will only get the DNS servers, not a ls list
of all computers on there.
0
 
Steve KnightIT ConsultancyCommented:
You can add an extra line in my script above where it creates the temporary nslookup script, i.e.

@echo off
(echo server 1.2.3.4
 echo ls yourdomain.local
 echo exit
)>>tempfile.txt
nslookup < tempfile.txt > output.txt
notepad output.txt

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Sorry that should be a dingle > in line 5, not >> otherwise the script will append each time.  It creates a temporary script tempfile.txt which is your commands then redirects them into nslookup with < and takes the output using > into output.txt then shows it you in notepad.
0
 
NeuronerAuthor Commented:
From dragon-it's comment I made this batch file:

@echo off
echo ls yourdomain.local >tempfile.txt
echo exit >>tempfile.txt
nslookup < tempfile.txt > output.txt
notepad output.txt
nslookup
> ls mydomainhere.net > C:\expert.txt
pause
exit

The output gave me a .txt listing my DNS server, and an error message telling
me I do not have the correct access to carry out the command. However, if
done manually on my PC, I get the output in cmd.
0
 
Steve KnightIT ConsultancyCommented:
OK, odd?  So the ls command works manually but not like this?  Can you try my new version posted pls?

Steve
0
 
Steve KnightIT ConsultancyCommented:
For me both returned output of a WIn 2000 DC DNS that was easy to connect to and check.
0
 
NeuronerAuthor Commented:
btw - I also got it to work with the tool dig

Thanks for helping!
0
 
Steve KnightIT ConsultancyCommented:
OK, well thanks for the answer then!

Steve
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now