Computing.Net > Forums > Programming > modify nslookup script to use batch

modify nslookup script to use batch

Reply to Message Icon

Original Message
Name: themac
Date: November 16, 2007 at 02:55:07 Pacific
Subject: modify nslookup script to use batch
OS: Windows XP
CPU/Ram: .
Model/Manufacturer: .
Comment:

Hi,

I have a bunch of ipaddresses that i need to know the DNS names of. i have a script and it works great. the only problem is that i have to manually enter the IP. Could someone help to modify this script so it will get the IP from a txt file or something like that.

My code is:
@ECHO OFF
SETLOCAL
SET SCRIPTNAME=%~n0
IF "%1"=="" ECHO Incorrect Syntax - use: %SCRIPTNAME% IPADDRESS && GOTO :EOF
FOR /F "tokens=3delims=: " %%I IN ('PING -n 1 %1 ^| FIND "Reply from"') DO (
SET IP=%%I
FOR /F "tokens=2 delims=:" %%J IN ('NSLOOKUP %%I ^| FIND "Name:"') DO SET DNS=%%J
)
IF NOT DEFINED IP @ECHO %1 is invalid or NETWORK error occurred. && GOTO :EOF
@ECHO.
IF NOT DEFINED DNS @ECHO %1 - invalid DNS name or DNS error occurred. && GOTO :EOF
echo %TIME% >> DNS.log
echo %DNS% >> DNS.log
@ECHO%DNS%
ENDLOCAL


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: November 16, 2007 at 05:15:51 Pacific
Subject: modify nslookup script to use batch
Reply: (edit)

The below script makes you able to use the native one as usual, i.e.

ScriptName IPaddress

or

Scriptname @FileName

where FileName is a text file with ONE IP on each line.

Beware the script was not tested.

@ECHO OFF
SETLOCAL
SET SCRIPTNAME=%~n0
IF "%1"=="" ECHO Incorrect Syntax - use: %SCRIPTNAME% IPaddress or @File_Of_IPaddresses && GOTO :EOF
Set Param=%1
If not "%Param:~0,1%"=="@" GoTo :RUN
Echo. Reading IP addresses from %Param:~1%
For /F %%a in (%Param:~1%) Do (
Call :RUN %%a)
Echo. List completed
GoTo :EOF

:RUN
FOR /F "tokens=3delims=: " %%I IN ('PING -n 1 %1 ^| FIND "Reply from"') DO (
SET IP=%%I
FOR /F "tokens=2 delims=:" %%J IN ('NSLOOKUP %%I ^| FIND "Name:"') DO SET DNS=%%J
)
IF NOT DEFINED IP @ECHO %1 is invalid or NETWORK error occurred. && GOTO :EOF
ECHO.
IF NOT DEFINED DNS @ECHO %1 - invalid DNS name or DNS error occurred. && GOTO :EOF
echo %TIME% >> DNS.log
echo %DNS% >> DNS.log
ECHO.%DNS%


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: modify nslookup script to use batch

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge