Recently I've been having problems with my internet connection. In order to find the problem in the chain I looked into some code I found online. I have never written code for a batch-file before, so just go ahead and expect me to know barrely anything. Anyway, I played around with it a bit and found out what each of the lines does.. to an extend at least. Now the results I'm getting from that file are included below as well. What I want to do is write a seperate file which I can run that takes the results from the first file and filters them into a new textfile.
I've already dug through some of the examples I've found here, but I don't simply want to copy paste (not that such a solution would work... I tried so I could reverse engineer it, but to no avail). I found some examples of how to get data from a file using a FOR and a FOREACH-Object, but it makes very little sense to me and I can't get it to work.
In short, I would like the pinging data that's placed in the first text file to be filtered by a batch file so it only sends part of the text to the new text file. Is anything like this possible and if so how do I go about this? Some explanation about how it works would be great as I like to take code apart and play around with it.
The code I use to get the pinging data whenever a connection fault is detected is listed below. I'm not saying it works perfectly mainly because I'm not 100% on how the %SystemRoot%-part works... But so far every time it triggers it also finds a request timeout. I'm open for suggestions to improve this but I would like for the focus to be on the noted challenge of extracting from one file and sending it to another.
:Loop
::Starting up the loop
PING -n 5 127.0.0.1 > NUL
::Set the ping delay
set Address=google.com
::Set the address to ping to google.com
%SystemRoot%\system32\ping.exe -n 1 %Address%|%SystemRoot%\system32\find.exe "TTL=" > NUL
::Check the connection
if %ERRORLEVEL% EQU 0 goto Loop
::If no error, return to Loop
::So if error, continue to next statement
echo Pinging %Address% >> D:\pingtest\Test\logfiletest.log
::Echo the pinging action
echo Trace route %Address% at %date% %time% >>
D:\pingtest\Test\logfiletest.log
::Echo the route to trace and the timestamp
tracert %Address% >> D:\pingtest\Test\logfiletest.log
::Echo the pinging and results
echo. >> D:\pingtest\Test\logfiletest.log
::Nextline
goto Loop
::Return to Loop
These are the results I'm getting that I'm trying to filter into the new file.
Pinging google.com
Trace route google.com at Fri 05/24/2019 10:22:40.92
Tracing route to google.com [172.217.168.238]
over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms MyLocation
2 13 ms 12 ms 13 ms 195.190.228.150
3 * * * Request timed out.
4 7 ms 10 ms 8 ms 139.156.127.75
5 7 ms 8 ms 9 ms 108.170.241.193
6 15 ms 18 ms 17 ms 72.14.238.245
7 8 ms 7 ms 7 ms ams16s31-in-f14.1e100.net [172.217.19.206]
Trace complete.
So that is the result I am currently getting from the batch-file that I made after looking at the suggested code for another issue. Now what I would like to see something along the lines of the following
Trace route google.com at Fri 05/24/2019 10:22:40.92
3 * * * Request timed out.
5 7 ms 8 ms 9 ms 108.170.241.193
I'm taking rows 3 and 5 as examples because they often return a 'Request timed out'
tracertdoesn't tell you anything useful. It only says that a particular server refuses to give an answer to apingrequest. As you can see (the list continues) that doesn't break the trace. What exactly do you want to achieve?