Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Batch IP pinging and displaying names.

$
0
0

Hi, 

I've found a great text file in an older thread located here - http://social.technet.microsoft.com/Forums/scriptcenter/en-US/c0cafc24-c9be-4f67-ada0-4bb05fb26e78/explain-the-batch-script-to-ping-multiple-computers?forum=ITCG

It basically generates a text file, displaying all the IPs listed in another text file and appends an either "alive" or "dead" state next to them.

@echo off
set fnm=c:\scripts\computers.txt
set lnm=c:\scripts\pingme.txt

if exist %fnm% goto Label1

echo.
echo Cannot find %fnm%
echo.
Pause
goto :eof

:Label1
echo PingTest STARTED on %date% at %time% >> %lnm%
echo ================================================= >> %lnm%
echo.
for /f %%i in (%fnm%) do call :Sub %%i
echo.
echo ================================================= >> %lnm%
echo PingTest ENDED on %date% at %time% >> %lnm%
echo ... now exiting
goto :eof

:Sub
echo Testing %1
set state=alive
ping -n 1 %1 
if errorlevel 1 set state=dead
echo %1 is %state% >> %lnm%

What I'd like to do is add an identifier/name to each IP in the referenced "computers.txt" text file and have that displayed next to the IP in the generated "pingme.txt" text file. 

Something that tells :Label1 to ignore the name but asks :Sub to print the name next to the IP.

Any help will be much apreciated.

Thanks, 

Victor.



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>