Ping computers with Time Stamp

Here it is: A small script that pings computer with Time Stamp:

@Echo off
echo %time% > c:\PingServer.txt
Ping 111.34.22.45 >> C:\PingServer.txt

Note the “>>” in above redirector. This redirector enables you to append the file rather than overwrite it.

Will sought more on this if time permits :)

[H]
 

20 thoughts on “Ping computers with Time Stamp”

  1. Hi Nirmal,

    I like this script idea. How would I turn it up a notch though? I’m looking to add a time stamp on every single reply I get back from the device I am pinging. How would I do that? For example:

    Pinging 172.25.0.60 with 32 bytes of data:

    8:54:52 Reply from 172.25.0.60: bytes=32 time=3ms TTL=64

    8:54:53 Reply from 172.25.0.60: bytes=32 time=2ms TTL=64

    8:54:54 Reply from 172.25.0.60: bytes=32 time=3ms TTL=64

    8:54:55 Reply from 172.25.0.60: bytes=32 time=2ms

    Ping statistics for 172.25.0.60:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

    Approximate round trip times in milli-seconds:

    Minimum = 2ms, Maximum = 4ms, Average = 2ms

    Is this possible?

  2. Thank you. This will assist me with something on which I’m working and will get me a few more hours sleep. I’ll possibly be able to go to church on sunday instead of monitoring a server.

  3. Let me tell you one thing. Ping command doesn’t support any API function. Meaning it won’t allow you to add your own command in each reply. You have to use mechanism provided by other users.

    You can not insert your own command in each reply.

    Nirmal.

  4. I also found that tool. And this is the command line I use to catch request-timed-out errors with timestamp:

    hrping -t -o -F c:\pingcheck.txt -qr -T -s 0 -w 997 example.com

    -t constant ping
    -o don’t do overlapped pinging (to be able to catch timestamps of request timed outs)
    -F log also to file
    -qr suppress normal replies (to not overflood log files/console)
    -T print timestamp
    -s time between two ping attempts (0ms)
    -w time to wait for reply (997ms)

    HTH

  5. Found a real simple cycle that did the job for me.

    @ECHO OFF
    :TOP

    FOR /F “tokens=3,4,5 delims= ” %%A IN (‘PING -a %1 -n 1 ^| FIND “Reply”‘) DO ECHO %DATE% %TIME% %%A %%B %%C >> pingpong.txt

    GOTO TOP

    hope this helps

  6. Looping with a sleep between attempts.
    Obtain sleep.exe from Windows Server 2003 Resource Kit Tools
    The path to Sleep.exe should also be given.

    :TOP

    echo %time%>>C:\PingServer.txt

    ping -w 20000 -n 1 -l 1 111.34.22.45>>C:\PingServer.txt

    C:\sleep 5
    GOTO TOP

  7. rem Try below

    @Echo off
    if “”%1″”==”””” goto HELP
    if “”%1″”==””/?”” goto HELP
    echo %0 %1

    set result=

    for /f “tokens=* delims= ” %%a in (‘ping %1 -n 1 ^| find /i “reply”‘) do (
    set result=”%%a”
    )

    if “”%result%””==”””” goto :IFELSE_PING
    for /f “tokens=3,4,5,6 delims= ” %%a in (%result%) do (
    set result=”%%a %%b %%c %%d”
    )
    goto ENDIF_PING
    :IFELSE_PING
    set result=”Request timed out.”
    :ENDIF_PING
    rem echo %result%

    :KEEP_PINGING
    for /f “tokens=* delims= ” %%a in (%result%) do (
    echo %date% %time% – %%a
    )
    sleep 1
    GOTO KEEP_PINGING

    :HELP
    echo usage: %0 IP/HOST

  8. hrping doesn’t work well with windows vista… is there any alternative tools for vista?

    D:\hrping-v244>hrping.exe -T 192.168.1.1
    This is hrPING v2.44 by cFos Software GmbH — http://www.cfos.de

    Pinging 192.168.1.1
    with 32 bytes data (60 bytes IP):

    4 Requests timed out.

    Statistics for 192.168.1.1:
    Packets: sent=4, rcvd=0, error=0, lost=4 (100% loss) in 0.000000 sec

    hrPing has known problems with Windows Vista and later raw sockets.
    Maybe a newer version of hrPing has already fixed them?

  9. starting time 15:13:26
    Pinging 172.25.0.60 with 32 bytes of data:

    8:54:52 Reply from 172.25.0.60: bytes=32 time=3ms TTL=64

    8:54:53 Reply from 172.25.0.60: bytes=32 time=2ms TTL=64

    8:54:54 Reply from 172.25.0.60: bytes=32 time=3ms TTL=64

    8:54:55 Reply from 172.25.0.60: bytes=32 time=2ms

    Ping statistics for 172.25.0.60:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

    end time 15:15:46

    any cmd to view like this?

  10. I’ve tweaked the script to:
    a) re-execute the ping each time (note the Goto Start in this script which is missing above)
    b) work on Windows 7 (which doesn’t appear to have a sleep command)
    c) as an enhancement, wait 10 seconds between successful pings, but only 2 between unsuccessful)

    @Echo off
    if “”%1″”==”””” goto HELP
    if “”%1″”==””/?”” goto HELP
    Rem
    Rem Show that this is running
    Rem
    echo %0 %1
    Rem
    :START
    set result=
    for /f “tokens=* delims= ” %%a in (‘ping %1 -n 1 ^| find /i “reply”‘) do (
    set result=”%%a”
    )
    if “”%result%””==”””” goto :IFELSE_PING
    for /f “tokens=3,4,5,6 delims= ” %%a in (%result%) do (
    set result=”%%a %%b %%c %%d”
    )
    set delay=10
    goto ENDIF_PING
    :IFELSE_PING
    set result=”Request timed out.”
    set delay=2
    :ENDIF_PING
    for /f “tokens=* delims= ” %%a in (%result%) do (
    echo %date% %time% – %%a
    )
    Rem sleep for delay seconds
    ping -n %delay% 127.0.0.1 > NUL 2>&1
    GOTO START
    :HELP
    echo usage: %0 IP/HOST

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>