windows环境
windows使用ping命令不想Linux那么方便,需要写个脚本来执行多条语句,内容如下:
@echo off
set filePath=C:/1.txt
set ping_url=www.baidu.com
set sleep_times=5
:top
echo starting test network...
echo %date% %time%>>%filePath%
ping %ping_url% -n 1|findStr "TTL" >> %filePath%
ping -n %sleep_times% 127.1 >nul
goto top
打印的日志(1.txt)
Linux环境
Linux下面执行一条命令即可
ping www.baidu.com | awk '{ print strftime("%Y.%m.%d %H:%M:%S",systime())"\t" $0 }'>> 1.txt
打印的日志(1.txt)