Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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%

![]() |
![]() |
![]() |

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