Pinging Multiple PCs and Adding Text

I am new to this, so please bear with me, and if you need more information from me, please tell me. Thanks in advance for your help.

I have this code that pings on different computers and then returns if they are online / offline. I wanted to know if another column could be added as soon as the bat file did its ping test so that it had the computer name next to it.

@echo off if exist C:\tools\computers.txt goto Label1 echo. echo Cannot find C:\tools\computers.txt echo. Pause goto :eof :Label1 echo PingTest executed on %date% at %time% > C:\tools\z.txt echo ================================================= >> C:\tools\z.txt for /f %%i in (C:\tools\computers.txt) do call :Sub %%i notepad C:\tools\z.txt goto :eof :Sub echo Testing %1 set state=alive ping -n 1 %1 | find /i "bytes=" || set state=dead echo %1 is %state% >> C:\tools\z.txt 

The bat file creates a document that shows the following:

PingTest on 07/28/2016 at 13:10:28

99.1.82.28 alive

99.1.82.100 alive

Ect.


If possible, I would like the bat file to be launched so that it displays this:

The bat file creates a document that shows the following:

PingTest on 07/28/2016 at 13:10:28

Computer 1: 99.1.82.28 is alive

Computer 2: 99.1.82.100 is alive

Ect.

-

Thank you for your help and guidance on this.

Thanks.

0
source share
1 answer

You can try this solution:

 @echo off Title Ping Test set "URLS=URLS.txt" set "LogFile=PingResults.txt" If exist %LogFile% Del %LogFile% ( echo ****************************************************** echo PingTest executed on %Date% @ Time %Time% echo ****************************************************** echo( ) > %LogFile% Setlocal EnableDelayedExpansion for /f "usebackq delims=" %%a in ("%URLS%") do ( for /f "tokens=2 delims=[]" %%b in ('ping -n 1 %%a') do set "ip=%%b" ping -n 1 %%a>nul && set "msg=%%a : !ip! ALive ok" || set "msg=%%a : !ip! Dead failed to respond" echo !msg! echo !msg! >> %LogFile% ) ) EndLocal Start "" %LogFile% pause>nul & exit 

EDIT: 07/29/2016 @ 12: 48

Another version with several colors: special thanks to ICARUS for the color function (-_ °)

enter image description here

 @echo off Rem Special thanks goes to Iracus for the color function (-_°) mode con cols=60 lines=20 Title Multi-Ping hosts Tester with Multi-colors by Hackoo set "URLS=URLS.txt" set "LogFile=PingResults.txt" If exist %LogFile% Del %LogFile% call :init echo( call :color 0E "------- Ping Status of Computers hosts -------" 1 echo( ( echo ****************************************************** echo PingTest executed on %Date% @ Time %Time% echo ****************************************************** echo( ) > %LogFile% Setlocal EnableDelayedExpansion for /f "usebackq delims=" %%a in ("%URLS%") do ( for /f "tokens=2 delims=[]" %%b in ('ping -n 1 %%a') do set "ip=%%b" ping -n 1 %%a>nul && set "msg=%%a - !ip! ALive ok" && Call :Color 0A "!msg!" 1 || set "msg=%%a - !ip! Dead failed to respond" && Call :Color 0C "!msg!" 1 echo !msg! >> %LogFile% ) ) EndLocal Start "" %LogFile% pause>nul & exit :init prompt $g for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a" exit /b :color set nL=%3 if not defined nL echo requires third argument & pause > nul & goto :eof if %3 == 0 ( <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof ) else if %3 == 1 ( echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof ) exit /b 

EDIT: 08/23/2016 update

http://pastebin.com/zjYwSqUM

0
source

All Articles