batch file to find hostnames from ip addresses of lot of machines

I need to find the hostnames from ip addresses of almost 50 machines. So I need to open a dos window and

issue ping -a ipaddress and then I get the reply form where I can get the ip address
like this
________________________________________________________________
C:\>ping -a ipaddress

Pinging hostname [ipaddress] with 32 bytes of data:

Reply from ipaddress: bytes=32 time=2ms TTL=122
Reply from ipaddress: bytes=32 time=2ms TTL=122
Reply from ipaddress: bytes=32 time=2ms TTL=122
Reply from ipaddress: bytes=32 time=2ms TTL=122

Ping statistics for ipaddress:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 2ms, Average = 2ms

________________________________________________________________

Now could somebody write a batch file for me which will be

batchfile inputfilename outputfilename

int the input file I will put all the ipaddresses

In the output file it should have the output as

ipaddress        hostname
10.555.55.55  hostname
anshumaEngineeringAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveGTRCommented:
Try this:

@echo off

setlocal

if "%~1"=="" echo Usage: %0 ipList [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 hostName=Not found

for /f "tokens=2 delims=[]" %%a in ('ping -a -n 1 %~1 2^>NUL ^| findstr /i Pinging') do set hostName=%%a

echo %~1 %hostName% >>"%outFile%"
anshumaEngineeringAuthor Commented:
Its not working. Its printing the ipaddresses again in the output file and the format of output is

ipaddress ipaddress
bmsjeffCommented:
komodo laboratories has a freeware program that will do this:
http://www.komodolabs.com/newtfree.shtml
SteveGTRCommented:
Sorry, I didn't change the delims from the last batch file I did for you. Also, I didn't look real closely at my output file. My mistake.

@echo off

setlocal

if "%~1"=="" echo Usage: %0 ipList [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 hostName=Not found

for /f "tokens=2" %%a in ('ping -a -n 1 %~1 2^>NUL ^| findstr /i Pinging') do set hostName=%%a

echo %~1 %hostName% >>"%outFile%"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.