I want to be able to ping a website such as www.google.com and then have it make a new text file with the results of said ping.
Here is the code of the ping:
echo --------------------
echo TESTING CONNECTIVITY
echo --------------------
ping 127.0.0.1 -n 5 -w 3000
echo.
ping www.google.com -n 5 -w 3000
I want that to be in a text file after it is done.
Pipe it to a file and use type to display the results also in the console
ping www.google.com > result.txt
type results.txt
or
ping www.google.com | result.txt
The latter one will open the result.txt to show the result.
Or put a type results.txt
after the ping to show the results on the console.
另一种方法是将批处理文件的输出传递到文本文件中:
mypingbatch.bat >>file.log
If you want to log availabily periodically, schedule the following task:
SET IP=www.google.com
SET STATUS=UNAVAILABLE
FOR /F "tokens=1-9 delims==< " %%a IN ('PING -n 1 -w 2500 %IP%') DO IF "%%h"=="TTL" SET STATUS=%%g
ECHO %DATE% %TIME% %IP% %STATUS% >> ping.%IP%.log
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.