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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

modify nslookup script to use batch

Reply to Message Icon

Name: themac
Date: November 16, 2007 at 02:55:07 Pacific
OS: Windows XP
CPU/Ram: .
Product: .
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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: November 16, 2007 at 05:15:51 Pacific
Reply:

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%


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: modify nslookup script to use batch

Using batch script print filenames in folder www.computing.net/answers/programming/using-batch-script-print-filenames-in-folder-/19171.html

using a vbs script to add reg value www.computing.net/answers/programming/using-a-vbs-script-to-add-reg-value/15420.html

How to seach *.mp3 etc using batch www.computing.net/answers/programming/how-to-seach-mp3-etc-using-batch/15950.html