help counting time-lenght per ping status of google.com

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bars143
Posts: 87
Joined: 01 Sep 2013 20:47

help counting time-lenght per ping status of google.com

#1 Post by bars143 » 01 Dec 2013 22:05

hi, to all experts,

could you help me make script based on code below:

Code: Select all

Pinging google.com [74.125.192.102] with 32 bytes of data:
Reply from 74.125.192.102: bytes=32 time=472ms TTL=48   <---start time
Reply from 74.125.192.102: bytes=32 time=435ms TTL=48
Reply from 74.125.192.102: bytes=32 time=441ms TTL=48
Reply from 74.125.192.102: bytes=32 time=422ms TTL=48
Reply from 74.125.192.102: bytes=32 time=510ms TTL=48
Reply from 74.125.192.102: bytes=32 time=412ms TTL=48   <---end time
Request timed out.        <---start time
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.        <---end time
Reply from 74.125.192.102: bytes=32 time=472ms TTL=48   <---start time
Reply from 74.125.192.102: bytes=32 time=435ms TTL=48
Reply from 74.125.192.102: bytes=32 time=441ms TTL=48   <---end time
Request timed out.        <---start time
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.        <---end time



explaining above by below description:

from line 2 to 7 <----with ping start: 7:00:09am 7:10:55am
from line 8 to 19 <----no ping start: 7:10:56am 7:22:34am
from line 20 to 22 <----with ping start: 7:22:35am 7:31:11am
from line 23 to 32 <----no ping start: 7:31:12am 7:44:00am


and i need output in text file named "ping_and_no-ping.txt " :

Code: Select all

____status_____start_________end______total-time__
with ping    7:00:09am   7:10:55am   00:10:55
no ping      7:10:56am   7:22:34am   ----?----
with ping    7:22:35am   7:31:11am   ----?----
no ping      7:31:12am   7:44:00am   -----?---



here is my code i made but could not finished to give result i suggested above:

Code: Select all


@echo off &setlocal enabledelayedexpansion

del ping_google_status.tmp 2>nul
del ping_and_no-ping.txt 2>nul

::scripts for timestamp to use in ping_and_no-ping.txt

echo i dont know timestamp code for use in ping_and_no-ping.txt
echo i will delete this if not needed.


:: pinging google and output result to ping_google_status.tmp

ping google.com -t >ping_google_status.tmp


:: count ping and no-ping lenght-time and
:: start appending length of time per ping status:

for /f "delims=" %%a in (' ping_google_status.tmp ^| find "^" ') do (

echo ____status_____start_________end______total-time__ >ping_and_no-ping.txt
echo here is lines of script i failed to create                       >>ping_and_no-ping.txt
echo next ping either ping or no ping                                >>ping_and_no-ping.txt
echo next ping either ping or no ping                                >>ping_and_no-ping.txt

)

type ping_and_no-ping.txt
pause
exit



thanks for helping me soon

bars
[/code]

penpen
Expert
Posts: 1859
Joined: 23 Jun 2013 06:15
Location: Germany

Re: help counting time-lenght per ping status of google.com

#2 Post by penpen » 02 Dec 2013 12:38

The "for /f" loop is buffering data, so you cannot add timestamps this way, see:
http://www.dostips.com/forum/viewtopic.php?p=30319#p30319
(I've figured that out just today. :D )

The following may be what you need:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set "state=undefined"
set LF=^


set ^"\n=^%LF%%LF%^%LF%"
set lastTimestamp=
set timestamp=
set "address=www.google.de"
set "tmpFile=ping_google_status.tmp"
set "targetFile=ping_and_no-ping.txt"
(
   for /F "tokens=1* delims=: " %%a in ('ping "%address%" -n 1 ^| findstr /N "^" ^| findstr "^2:"') do (
      set "line=%%b"
      (set /P "=!line:~0,-1!")<nul
   )
   for /L %%n in (1,1,20) do (
      for /F "tokens=1,2* delims=: " %%a in ('ping "%address%" -n 1 ^| findstr /N "^" ^| findstr "^4:"') do (
         set line=%%b %%c
         set "line=!line:~0,-1!"
         set "lastTimestamp=!timestamp!"
         set "timestamp= ^<---- !time!"

         if "!state!" == "%%a" (
            (set /P "=!\n!!line!")<nul
         ) else (
            (set /P "= !lastTimestamp!!\n!!line! !timestamp!")<nul
            set "state=%%a"
         )

      )
   )
   (set /P "= !lastTimestamp!!\n!")<nul
) > "%tmpFile%"

(
   set "state="
   set "reply=Reply"

   echo ____status_____start_________end______total-time__

   for /F "tokens=1* delims=<-" %%a in ('findstr "<----" "%tmpFile%"') do (
      for /F %%c in ("%%a") do (
         if "%%c" == "!state!" (
            echo   %%b   @todo: compute difftime
         ) else (
            if "!state!" == "!reply!" (
               (set /P "=no ping      %%b")<nul
            ) else (
               (set /P "=with ping    %%b")<nul
            )
            set "state=%%c"
         )
      )
   )

) > "%targetFile%"

del "%tmpFile%"

endlocal
The difftime value still has to be computed ("@todo: compute difftime").
The problem of am/pm is thate there are two possible cases how to read it; both are in use (in different countries of course; maybe there are more cases i don't know):
1) 00:00 am == 00:00, 00:xx am == 00:xx, 00:00 pm == 12:00, 00:xx pm == 12:xx
2) 00:00pm == 00:00, 00:xxam == 00:xx, 00:00am == 12:00, 00:xx pm == 12:xx

If this script should run on multiple PC, you may replace the timestamp with something more robust, see:
http://www.dostips.com/forum/viewtopic.php?f=3&t=4847
(You may also use the linked method to compute the difftime.)

penpen

Edit: The script above assumes that the needed informations are in specific lines:

Code: Select all

Z:\>ping "www.google.de" -n 1 | findstr /N "^"
1:
2:Ping www.google.de [173.194.69.94] mit 32 Bytes Daten:
3:
4:Antwort von 173.194.69.94: Bytes=32 Zeit=68ms TTL=50
5:
6:Ping-Statistik für 173.194.69.94:
7:    Pakete: Gesendet = 1, Empfangen = 1, Verloren = 0 (0% Verlust),
8:Ca. Zeitangaben in Millisek.:
9:    Minimum = 68ms, Maximum = 68ms, Mittelwert = 68ms
If the information in your version of ping is in different files, just replace the "^2" and "^4" with the right values:"^[line number of interest]".

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: help counting time-lenght per ping status of google.com

#3 Post by bars143 » 02 Dec 2013 22:10

hi penpen,

your codes always give me a second though and decided to minimize my problems (and only one script fourth-one is missing, read below),

but first i had to revise to better understand my suggestion,
here is my new statement (and forget some of my first post statement):

i found a script from foxidrive when i search "ping with timestamp" in dostips :

[i edited foxi's script below to suit my usage]

Code: Select all

@echo off
set "file=c:\users\jocelyn\desktop2\ping_list.txt"
set ip=www.google.com

setlocal enabledelayedexpansion
:loop
for /f "delims=" %%a in ('ping %ip% -n 1 ^|findstr "Reply Request" ') do >> "%file%" echo %%a - !time!&echo %%a
goto :loop


ouput of ping_list.txt (note: my netbook is a 12-hour format):

Code: Select all

Request timed out. -  8:07:50.28
Request timed out. -  8:07:54.27
Request timed out. -  8:07:58.26
Request timed out. -  8:08:02.26
Request timed out. -  8:08:06.41
Reply from 74.125.192.147: bytes=32 time=430ms TTL=48 -  8:08:27.89
Reply from 74.125.192.147: bytes=32 time=438ms TTL=48 -  8:08:28.47
Reply from 74.125.192.147: bytes=32 time=443ms TTL=48 -  8:08:29.03
Reply from 74.125.192.147: bytes=32 time=509ms TTL=48 -  8:08:29.64
Reply from 74.125.192.147: bytes=32 time=431ms TTL=48 -  8:08:30.20
Reply from 74.125.192.147: bytes=32 time=435ms TTL=48 -  8:08:30.78
Reply from 74.125.192.147: bytes=32 time=428ms TTL=48 -  8:08:31.31
Reply from 74.125.192.147: bytes=32 time=519ms TTL=48 -  8:08:31.91
Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.43
Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.97
Reply from 74.125.192.147: bytes=32 time=445ms TTL=48 -  8:08:33.51
Reply from 74.125.192.147: bytes=32 time=427ms TTL=48 -  8:08:34.04
Request timed out. -  8:08:37.76
Request timed out. -  8:08:42.26
Request timed out. -  8:08:46.27
Request timed out. -  8:08:50.26
Request timed out. -  8:08:54.27
Request timed out. -  8:08:58.26



then next i use this code(to add series number to every-line):

Code: Select all

@echo off &setlocal
del ping_list.txt

set "file=ping_list.txt"

for /f "delims=" %%i in ('type "%file%"^|find /v /n ""') do (
echo %%i >>ping_google_status.tmp
)

pause


and the output of ping_google_status.tmp is:

Code: Select all

[1]Request timed out. -  8:07:50.28 
[2]Request timed out. -  8:07:54.27
[3]Request timed out. -  8:07:58.26
[4]Request timed out. -  8:08:02.26
[5]Request timed out. -  8:08:06.41
[6]Reply from 74.125.192.147: bytes=32 time=430ms TTL=48 -  8:08:27.89
[7]Reply from 74.125.192.147: bytes=32 time=438ms TTL=48 -  8:08:28.47
[8]Reply from 74.125.192.147: bytes=32 time=443ms TTL=48 -  8:08:29.03
[9]Reply from 74.125.192.147: bytes=32 time=509ms TTL=48 -  8:08:29.64
[10]Reply from 74.125.192.147: bytes=32 time=431ms TTL=48 -  8:08:30.20
[11]Reply from 74.125.192.147: bytes=32 time=435ms TTL=48 -  8:08:30.78
[12]Reply from 74.125.192.147: bytes=32 time=428ms TTL=48 -  8:08:31.31
[13]Reply from 74.125.192.147: bytes=32 time=519ms TTL=48 -  8:08:31.91
[14]Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.43
[15]Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.97
[16]Reply from 74.125.192.147: bytes=32 time=445ms TTL=48 -  8:08:33.51
[17]Reply from 74.125.192.147: bytes=32 time=427ms TTL=48 -  8:08:34.04
[18]Request timed out. -  8:08:37.76
[19]Request timed out. -  8:08:42.26
[20]Request timed out. -  8:08:46.27
[21]Request timed out. -  8:08:50.26
[22]Request timed out. -  8:08:54.27
[23]Request timed out. -  8:08:58.26



then in timestamps, i need no date but just hours only and i can convert "8:08:37.76" via [8x60x60x60] + [8x60x60] + [37x60] = [ 1759020 seconds] by using this code:

Code: Select all

@echo off &setlocal enabledelayedexpansion

for /f "tokens=1 delims=:" %%a in (connected.txt) do (
     set "m=%%a"
    rem echo m=!m!
     set /a "n=!m! * 216000"
    rem echo n=!n!
          for /f "tokens=2 delims=:" %%b in (connected.txt) do (
          set "p=%%b"
        set p2=!p:~1!
          set /a "w= !p2! * 3600"
        set /a "s=!n! + !w!"
        rem echo w=!w!
            for /f "tokens=3 delims=:." %%c in (connected.txt) do (
               set "e=%%c"
               set "e2=!e:~2,0!
               rem echo e2=!e!
               set "r=!e! * 60"
               set /a "min=!s! + !r!"
               echo over-all-total-seconds=!min!
     )
    )
    )
pause
         


connected.txt output is: 8:08:37.76

then run with this code below to compute for length of time in seconds only:

Code: Select all

set "a=first-str"
set "b=last-str"
set "c=total-time"
set /a "!c!=!B! - !a!"
echo total time-in-seconds=!c!



now what i missed is a script as describe below:


a.) first i need script that extract first and last string "Request" that are same and continuous until last "Request"-str before "Reply" str ?

b.) then next run is for "reply" string and then extracted and coded with like above.

c.) and do next run on 3rd group which is "Request"-string

and thats is where i cant create myself for that above.


finally, i had the scattered 3 batch codes above to work


1.) pinging Google.com
2.) adding series number in every-line in a text file
3.) conversion and computing time-stamp to produce seconds ( and no date).
4.) cant create fourth script to extract first and last same str.


but cant combined to produce what i desired from four batch-scripts to one batch-script (yet the fourth-one im looking for is yet to create) - which can extract first and last same string in each different group of same string (only two type of str to find "Request" and "Reply") in a text-file given above named list.txt.
if scripts work , then we can extracted time-stamp to compute for length of time.

but what i desired-result is the same (without am/pm):


Code: Select all

____status_____start_________end______total-time__
with ping      7:00:09          7:10:55       00:10:55
no ping         7:10:56          7:22:34      ----?----
with ping      7:22:35          7:31:11      ----?----
no ping         7:31:12          7:44:00      -----?---


or alternative:

Code: Select all

____status_____start_________end______total-time_in_seconds_
with ping       7:00:09        7:10:55         655 seconds
no ping          7:10:56        7:22:34         ----?----
with ping       7:22:35        7:31:11          ----?----
no ping          7:31:12        7:44:00         -----?---



above result is needed for my study to that i can choose stable time to surf [only if stable-connection-pattern found out to be constant daily].

============================
here is my code i made yet incomplete: :?

Code: Select all

@echo off 
del ping_google_status.tmp 2>nul
del ping_and_no-ping.txt 2>nul

:: pinging google and output result to ping_list.txt

set "file=c:\users\jocelyn\desktop2\ping_list.txt"
set ip=www.google.com

setlocal enabledelayedexpansion
set "count=0"
:loop
for /f "delims=" %%a in ('ping %ip% -n 1 ^|findstr "Reply Request" ') do (
set /a "count+=1"
>> "%file%" echo %%a - !time!&echo %%a
if !count! equ 100 goto :next
)
goto :loop

:next
endlocal
setlocal
rem series numbering of everyline and redirected to ping_google_status.tmp

for /f "delims=" %%i in ('type "%file%"^|find /v /n ""') do (
echo %%i >>ping_google_status.tmp
)

:: below are missing code/script to be filled-up to work,
:: [its a fourth scripts i cant create yet,]
:: start appending length of time for "reply and request str":

for /f "delims=" %%a in (' ping_google_status.tmp ^| findstr /i "Reply Request" ') do (

echo ____status_____start_________end______total-time__ >ping_and_no-ping.txt

rem from line [1] to [5]
rem first i need script that extract first and
rem last string "Request" that are continuous
rem then run script for length of time

echo missing scripts to be filled-up >>ping_and_no-ping.txt

echo second run is:

rem from line [6] to [17]
rem first i need script that extract first and
rem last string "Reply" that are continuous
rem then run script for length of time

echo missing scripts to be filled-up >>ping_and_no-ping.txt

echo third run is:

rem from line [18] to [23]
rem first i need script that extract first and
rem last string "Request" that are continuous
rem then run script for length of time

echo missing scripts to be filled-up >>ping_and_no-ping.txt

)
rem after creating/filled up missing scripts
rem then read file below for results

type ping_and_no-ping.txt

rem and if working then a big thanks to those who helps !!!

pause
exit


==========================
sorry of some major adjustment and some typos. :oops:

bars

penpen
Expert
Posts: 1859
Joined: 23 Jun 2013 06:15
Location: Germany

Re: help counting time-lenght per ping status of google.com

#4 Post by penpen » 03 Dec 2013 07:16

If i understand you right, then you only want a batch script, that transforms the file named "ping_google_status.tmp"

Code: Select all

[1]Request timed out. -  8:07:50.28 
[2]Request timed out. -  8:07:54.27
[3]Request timed out. -  8:07:58.26
[4]Request timed out. -  8:08:02.26
[5]Request timed out. -  8:08:06.41
[6]Reply from 74.125.192.147: bytes=32 time=430ms TTL=48 -  8:08:27.89
[7]Reply from 74.125.192.147: bytes=32 time=438ms TTL=48 -  8:08:28.47
[8]Reply from 74.125.192.147: bytes=32 time=443ms TTL=48 -  8:08:29.03
[9]Reply from 74.125.192.147: bytes=32 time=509ms TTL=48 -  8:08:29.64
[10]Reply from 74.125.192.147: bytes=32 time=431ms TTL=48 -  8:08:30.20
[11]Reply from 74.125.192.147: bytes=32 time=435ms TTL=48 -  8:08:30.78
[12]Reply from 74.125.192.147: bytes=32 time=428ms TTL=48 -  8:08:31.31
[13]Reply from 74.125.192.147: bytes=32 time=519ms TTL=48 -  8:08:31.91
[14]Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.43
[15]Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.97
[16]Reply from 74.125.192.147: bytes=32 time=445ms TTL=48 -  8:08:33.51
[17]Reply from 74.125.192.147: bytes=32 time=427ms TTL=48 -  8:08:34.04
[18]Request timed out. -  8:08:37.76
[19]Request timed out. -  8:08:42.26
[20]Request timed out. -  8:08:46.27
[21]Request timed out. -  8:08:50.26
[22]Request timed out. -  8:08:54.27
[23]Request timed out. -  8:08:58.26
...
to a file named "ping_and_no-ping.txt":

Code: Select all

____status_____start_________end______total-time__
no reply        8:07:50     8:08:06    0:00:16 (16 secs)
with reply      8:08:27     8:08:34    0:00:07 (7 secs)
no reply        8:08:37     8:08:58    0:00:21 (21 secs)
.

Then this may help you:

Code: Select all

@echo off
setlocal enableDelayedExpansion

set "state="
set "reply=Reply"
set "tmpFile=ping_google_status.tmp"
set "targetFile=ping_and_no-ping.txt"

set "state=undefined"
set "firstTimestamp="
set "timestamp="
set "label=undefined"
(
   echo ____status_____start_________end______total-time__
   for /F "tokens=1* delims=-" %%a in ('findstr " - " "%tmpFile%"') do (
      for /F "tokens=2 delims=] " %%c in ("%%a") do (
         if NOT "!state!" == "%%c" (
            if NOT "!state!" == "undefined" (
               set "dt=((((0:!timestamp: =!)-((((0:!firstTimestamp: =!)"
               set "dt=!dt::0=:!"
               set "dt=!dt:::=:0:!"
               set /A "dth=(dt=!dt::=)*60+!)/3600"
               set /A "dtm=((dt-(dts=dt%%60))/60)%%60"
               if !dts! LSS 10 set "dts=0!dts!"
               if !dtm! LSS 10 set "dtm=0!dtm!"

               echo !label!    !firstTimestamp!   !timestamp!    !dth!:!dtm!:!dts! ^(!dt! secs^)
               
            )
            set "state=%%c"
            for /F "delims=.," %%t in ("%%b") do set "timestamp=%%t"

            if "!state!" == "!reply!" (
               set "label=with reply"
            ) else (
               set "label=no reply  "
            )
            set "firstTimestamp=!timestamp!"
         ) else (
            for /F "delims=.," %%t in ("%%b") do set "timestamp=%%t"
         )
      )
   )

   set "dt=((((0:!timestamp: =!)-((((0:!firstTimestamp: =!)"
   set "dt=!dt::0=:!"
   set "dt=!dt:::=:0:!"
   set /A "dth=(dt=!dt::=)*60+!)/3600"
   set /A "dtm=((dt-(dts=dt%%60))/60)%%60"
   if !dts! LSS 10 set "dts=0!dts!"
   if !dtm! LSS 10 set "dtm=0!dtm!"

   echo !label!    !firstTimestamp!   !timestamp!    !dth!:!dtm!:!dts! ^(!dt! secs^)
) > "%targetFile%"


endlocal
goto :eof

penpen

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: help counting time-lenght per ping status of google.com

#5 Post by bars143 » 03 Dec 2013 18:15

penpen wrote:If i understand you right, then you only want a batch script, that transforms the file named "ping_google_status.tmp"

Code: Select all

[1]Request timed out. -  8:07:50.28 
[2]Request timed out. -  8:07:54.27
[3]Request timed out. -  8:07:58.26
[4]Request timed out. -  8:08:02.26
[5]Request timed out. -  8:08:06.41
[6]Reply from 74.125.192.147: bytes=32 time=430ms TTL=48 -  8:08:27.89
[7]Reply from 74.125.192.147: bytes=32 time=438ms TTL=48 -  8:08:28.47
[8]Reply from 74.125.192.147: bytes=32 time=443ms TTL=48 -  8:08:29.03
[9]Reply from 74.125.192.147: bytes=32 time=509ms TTL=48 -  8:08:29.64
[10]Reply from 74.125.192.147: bytes=32 time=431ms TTL=48 -  8:08:30.20
[11]Reply from 74.125.192.147: bytes=32 time=435ms TTL=48 -  8:08:30.78
[12]Reply from 74.125.192.147: bytes=32 time=428ms TTL=48 -  8:08:31.31
[13]Reply from 74.125.192.147: bytes=32 time=519ms TTL=48 -  8:08:31.91
[14]Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.43
[15]Reply from 74.125.192.147: bytes=32 time=436ms TTL=48 -  8:08:32.97
[16]Reply from 74.125.192.147: bytes=32 time=445ms TTL=48 -  8:08:33.51
[17]Reply from 74.125.192.147: bytes=32 time=427ms TTL=48 -  8:08:34.04
[18]Request timed out. -  8:08:37.76
[19]Request timed out. -  8:08:42.26
[20]Request timed out. -  8:08:46.27
[21]Request timed out. -  8:08:50.26
[22]Request timed out. -  8:08:54.27
[23]Request timed out. -  8:08:58.26
...
to a file named "ping_and_no-ping.txt":

Code: Select all

____status_____start_________end______total-time__
no reply        8:07:50     8:08:06    0:00:16 (16 secs)
with reply      8:08:27     8:08:34    0:00:07 (7 secs)
no reply        8:08:37     8:08:58    0:00:21 (21 secs)
.

Then this may help you:

Code: Select all

@echo off
setlocal enableDelayedExpansion

set "state="
set "reply=Reply"
set "tmpFile=ping_google_status.tmp"
set "targetFile=ping_and_no-ping.txt"

set "state=undefined"
set "firstTimestamp="
set "timestamp="
set "label=undefined"
(
   echo ____status_____start_________end______total-time__
   for /F "tokens=1* delims=-" %%a in ('findstr " - " "%tmpFile%"') do (
      for /F "tokens=2 delims=] " %%c in ("%%a") do (
         if NOT "!state!" == "%%c" (
            if NOT "!state!" == "undefined" (
               set "dt=((((0:!timestamp: =!)-((((0:!firstTimestamp: =!)"
               set "dt=!dt::0=:!"
               set "dt=!dt:::=:0:!"
               set /A "dth=(dt=!dt::=)*60+!)/3600"
               set /A "dtm=((dt-(dts=dt%%60))/60)%%60"
               if !dts! LSS 10 set "dts=0!dts!"
               if !dtm! LSS 10 set "dtm=0!dtm!"

               echo !label!    !firstTimestamp!   !timestamp!    !dth!:!dtm!:!dts! ^(!dt! secs^)
               
            )
            set "state=%%c"
            for /F "delims=.," %%t in ("%%b") do set "timestamp=%%t"

            if "!state!" == "!reply!" (
               set "label=with reply"
            ) else (
               set "label=no reply  "
            )
            set "firstTimestamp=!timestamp!"
         ) else (
            for /F "delims=.," %%t in ("%%b") do set "timestamp=%%t"
         )
      )
   )

   set "dt=((((0:!timestamp: =!)-((((0:!firstTimestamp: =!)"
   set "dt=!dt::0=:!"
   set "dt=!dt:::=:0:!"
   set /A "dth=(dt=!dt::=)*60+!)/3600"
   set /A "dtm=((dt-(dts=dt%%60))/60)%%60"
   if !dts! LSS 10 set "dts=0!dts!"
   if !dtm! LSS 10 set "dtm=0!dtm!"

   echo !label!    !firstTimestamp!   !timestamp!    !dth!:!dtm!:!dts! ^(!dt! secs^)
) > "%targetFile%"


endlocal
goto :eof

penpen


penpen,

your code is working !!! :idea:

thanks sa reply and im now start studying your code .

cheers !

bars

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: help counting time-lenght per ping status of google.com

#6 Post by bars143 » 03 Dec 2013 19:15

Code: Select all

@echo off
::  inserting codes to penpen:
::  one script to take ping output to "ping_list.txt"
::  add one script to stop ping at 100,
::  converted "ping_list.txt" with series # to "ping_google_status.tmp"

del "c:\users\jocelyn\desktop2\ping_list.txt"
del ping_google_status.tmp 2>nul
del ping_and_no-ping.txt 2>nul

:: pinging google and output result to ping_list.txt

set "file=c:\users\jocelyn\desktop2\ping_list.txt"
set ip=www.google.com

setlocal enabledelayedexpansion

set "count=0"
:loop
for /f "delims=" %%a in ('ping %ip% -n 1 ^|findstr "Reply Request" ') do (
set /a "count+=1"
>> "%file%" echo %%a - !time!&echo %%a
rem  insert count code to stop ping at 100:
if !count! equ 100 goto :next
)
goto :loop

:next
endlocal
setlocal

::  series numbering of everyline and redirected to ping_google_status.tmp

for /f "delims=" %%i in ('type "%file%"^|find /v /n ""') do (
echo %%i >>ping_google_status.tmp
)

::  i added two codes to avoid error due to "unbalance parenthesis" :
::  endlocal
::  setlocal enabledelayedexpansion

endlocal
setlocal enabledelayedexpansion

:: below are penpen's code:

set "state="
set "reply=Reply"
set "tmpFile=ping_google_status.tmp"
set "targetFile=ping_and_no-ping.txt"

set "state=undefined"
set "firstTimestamp="
set "timestamp="
set "label=undefined"
(
   echo ____status_____start_________end______total-time__
   for /F "tokens=1* delims=-" %%a in ('findstr " - " "%tmpFile%"') do (
      for /F "tokens=2 delims=] " %%c in ("%%a") do (
         if NOT "!state!" == "%%c" (
            if NOT "!state!" == "undefined" (
               set "dt=((((0:!timestamp: =!)-((((0:!firstTimestamp: =!)"
               set "dt=!dt::0=:!"
               set "dt=!dt:::=:0:!"
               set /A "dth=(dt=!dt::=)*60+!)/3600"
               set /A "dtm=((dt-(dts=dt%%60))/60)%%60"
               if !dts! LSS 10 set "dts=0!dts!"
               if !dtm! LSS 10 set "dtm=0!dtm!"

               echo !label!    !firstTimestamp!   !timestamp!    !dth!:!dtm!:!dts! ^(!dt! secs^)
               
            )
            set "state=%%c"
            for /F "delims=.," %%t in ("%%b") do set "timestamp=%%t"

            if "!state!" == "!reply!" (
               set "label=with reply"
            ) else (
               set "label=no reply  "
            )
            set "firstTimestamp=!timestamp!"
         ) else (
            for /F "delims=.," %%t in ("%%b") do set "timestamp=%%t"
         )
      )
   )

   set "dt=((((0:!timestamp: =!)-((((0:!firstTimestamp: =!)"
   set "dt=!dt::0=:!"
   set "dt=!dt:::=:0:!"
   set /A "dth=(dt=!dt::=)*60+!)/3600"
   set /A "dtm=((dt-(dts=dt%%60))/60)%%60"
   if !dts! LSS 10 set "dts=0!dts!"
   if !dtm! LSS 10 set "dtm=0!dtm!"

   echo !label!    !firstTimestamp!   !timestamp!    !dth!:!dtm!:!dts! ^(!dt! secs^)
) > "%targetFile%"


endlocal
goto :eof


above code is working to my dell netbook window7 32-bit 1gb-RAM :D

edited to add code, "del c:\users\jocelyn\desktop2\ping_list.txt"

-------------------------------------------
its really take time (for a newbie like me) to study penpen's working code
and its a big :idea: too to work on it.


thanks again to penpen,

bars

Post Reply