i would like to ask for some help with the output of tracert in windows, ie i have this output :
Tracing route to Y.Y.Y.Y over a maximum of 30 hops
1 1 ms 1 ms 1 ms X.X.X.X
2 103 ms 71 ms 22 ms X.X.X.X
3 35 ms 51 ms 35 ms X.X.X.X
....
and i would like to produce a file that contains only the X.X.X.X or as an intermediate step to get there, only the lines of tracer that actually contain IPs. Ie :
X.X.X.X
X.X.X.X
X.X.X.X
I ve tried this through a batch file :
for /f "tokens=8" %%a in ('tracert -4 -d 8.8.8.8^|find "ms"') do (
@echo %%a >D:\panagos\desktop\ips.txt
)
but instead of the desired output i get only :
Y.Y.Y.Y
I ve also tried calling on binaries from cygwin to do this, ie :
D:\path\to\slash\bin\awk '{ print $8 }' filein > fileout
but that doesnt work either. Can anyone help? Thanks in advance.
Use the following batch file:
GetIPs.cmd:
Example:
Further Reading
Read Redirection:
Use either
or (better)
Also note that your script hides unreachable hosts, see that 12th hop in next example has only 7 tokens: