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.
bars