Link to home
Start Free TrialLog in
Avatar of eric godthelp
eric godthelp

asked on

Ping record but only pings higher then <1ms

I got this script now running

@echo off

set /p host=host Address:
set logfile=Log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    timeout 1 >NUL
    GOTO Ping)

But i want it so that all the Pings that are <1ms are not recorded.
Is this possible?
Avatar of Bill Prew
Bill Prew

Give this a try, it looks for "time<1ms" in the ping response and only logs if not found.

@echo off
setlocal

set /p host=host Address:
set logfile=Log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (
  echo %%A>>%logfile%
  goto Ping
)

:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    find /i "time<1ms" >NUL || (
        echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
        echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    )
    timeout 1 >NUL
    goto Ping
)

Open in new window


»bp
Avatar of eric godthelp

ASKER

If i use that script if i have a timeout it wont record it either.

If i change the time<1ms too time<0ms. it also records nothing
Okay, try this:

@echo off
setlocal

set /p host=host Address:
set logfile=Log_%host%.log

echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (
    echo %%A>>%logfile%
    goto Ping
)

:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
    echo.%%A|find /i "time<1ms" >NUL && (
        timeout 1 >NUL
        goto Ping
    )
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
    echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
    timeout 1 >NUL
    goto Ping
)

Open in new window


»bp
All i get in the Log is:

Target Host = 192.168.255.135
Pinging 192.168.255.135 with 32 bytes of data:


I set the Time<100ms  to test it
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks you very much.

This works perfectly