Nslookup in batch for loop - why isn't it working?

LZozzy picture LZozzy · Jan 3, 2014 · Viewed 8.3k times · Source

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

Answer

user3771493 picture user3771493 · Jun 24, 2014

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.