2

I've created a batch script to read IP addresses or hostnames from a file, and feed them to nslookup, however when I run the script, it says that the system did not find the file.

What am I doing wrong?

Here's the code:

@echo off
setlocal enableextensions enabledelayedexpansion
if exist hostnames.txt del hostnames.txt
for /F %%A in (%1) do nslookup %%A >> hostnames.txt

Thanks in advance

LZozzy
  • 21
  • 1
  • 2
  • that line begins with "IF EXIST", so I'm sure that is not the problem. The file it says is missing is called the current IP address from the list file. The system cannot find the file 10.1.214.146. – LZozzy Jan 03 '14 at 10:05
  • 3
    Did you call the batch file nslookup? Try using a different name. – foxidrive Jan 03 '14 at 10:06
  • 2
    @foxidrive - yes I did... I renamed it, now it works, thank you :) – LZozzy Jan 06 '14 at 10:10
  • You can create an answer, mark it as answer, and get more happiness from life. – Lizz Feb 18 '14 at 19:23

2 Answers2

2

I wrote something similar. This works (you can remove the pause):

REM @echo off
del nslookup.txt 2>nul
pause
for /f "delims=" %%a in (c:\tools\server.txt) do NSLOOKUP %%a >> c:\tools\nslookup.txt

Results in txt file:

Name:    server1.XXXX.com
Address:  xxx.XX.XXX.XXX

Server:  server2.XXXX.com
Address:  xxx.XX.XXX.XX

etc.

Dan
  • 9,391
  • 5
  • 41
  • 73
0

Try this command.

:loop
 c:\windows\system32\nslookup.exe domainname >>D:\test\Hostname.txt
 timeout /t 300
goto loop
Ben Wong
  • 1
  • 1