ncomper
asked on
Batch File to dump list of Hostnames to IP Addresses
Hi, have a text file with 500 hostnames which I need to get the IP address for to create some firewall rules for.
I have seen the below batch but not sure how to apply it I have hostnames.txt and would like a simple batch file to ping all the results and then put into output.txt HOSTNAME xxx.xxx.xxx.xxx
Could anyone help me with that before I start doing them 1 by 1.
Regards
@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=2 delims=[]" %%a in ('ping -n 1 %~1') do set ipAddr=%%a
echo %~1 %ipAddr% >>"%outFile%"
hostnames.txt
I have seen the below batch but not sure how to apply it I have hostnames.txt and would like a simple batch file to ping all the results and then put into output.txt HOSTNAME xxx.xxx.xxx.xxx
Could anyone help me with that before I start doing them 1 by 1.
Regards
@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=2 delims=[]" %%a in ('ping -n 1 %~1') do set ipAddr=%%a
echo %~1 %ipAddr% >>"%outFile%"
hostnames.txt
ASKER
Didnt seem to work do I just paste this into a .bat file and run it ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dude Sirbounty,
That is a sweet script. I just tried it for funsies. You are Smart!
--> Another Question added to my Knowledgebase.
- gurutc
That is a sweet script. I just tried it for funsies. You are Smart!
--> Another Question added to my Knowledgebase.
- gurutc
ASKER
Amazing thank you
Glad I could help both of you. :^)
Thanx for the grade!
Thanx for the grade!
Thank you.
Open in new window