If you use this method, it required Cygwin because Windows doesn't have a host command, otherwise REM for for line with host and unREM the line with ping
Have a text file with the host names. Save the batch file below to hosttoip.bat and execute like this
hosttoip.bat hoststolookup.txt hostoutput.txt
@echo off
setlocal
if "%~1"=="" echo Usage: %0 serverList [outfile]&goto :EOF
if not exist "%~1" echo %~1 does not exist&goto :EOF
set outFile=%~2
if "%~2"=="" set outFile=outfile.txt
if exist "%outFile%" del "%outFile%"
for /f "tokens=*" %%a in ('type "%~1"') do call :PROCESS "%%a"
echo Results in %outFile%
goto :EOF
:PROCESS
set ipAddr=Not found
for /f "tokens=3 delims= " %%r in ('host %~1|find /i "Address"') do set ipAddr=%%r
REM for /f "tokens=4 delims= " %%r in ('ping -n 1 %~1|find /i "Statistics"') do set ipAddr=%%r
echo %~1 %ipAddr% >>"%outFile%"
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment