This is something simple I’m missing I bet and I have a feeling it’s not working the way I need because of the nested loop. This is a simple script I’ve pulled off somewhere and have modified a bit to allow for more testing. Essentially it just pings a host on a delay over and over for all time until you close it, but logs the failed responses. Everything works, but for the life of me I can’t figure out how to get it to update the name being used in the for loop.
@echo off
setlocal enabledelayedexpansion
:: ** Enter name to identify host in log **
set name1=Test 1
set name2=Test 2
set name3=Test 3
:: ** Enter IP or HOSTNAME to test against **
set hostIP1=1.1.1.1
set hostIP2=2.2.2.2
set hostIP3=3.3.3.3
:: ** Enter Delay in milliseconds between each test **
set delayMS=2000
title -DO NOT CLOSE- Ping Test
echo DO NOT CLOSE
echo Ping Test
:loop
set namecount=1
for %%x in (%hostIP1% %hostIP2% %hostIP3%) do (
set pingline=1
set pingname=name!namecount!
for /f "delims=" %%A in ('ping -n 1 -w 2000 -l 255 %%x') do (
if !pingline! equ 2 (
set logline=!date! !time! "%%A" - %%x !%pingname%!
echo !logline! | find "TTL=">nul || echo !logline! >> pinglog.txt
)
set /a pingline+=1
)
set /a namecount+=1
)
sleep -m %delayMS%
goto loop
Usually I’d use another language but I need something that works on windows servers of all kinds.. This seems like the surest way. Thanks
This is incorrect:
Try this:
I can’t try your code but i’ve made other minor corrections:
(UPDATED)