lys*_*xic 7 vbscript ping traceroute batch-file
我想连续ping我的家庭公共IP地址,如果ping失败,则自动执行traceroute以查看它的失败位置.
我一直在努力遵循这里的评论:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/efc97c66-60a6-4fd7-8be4-4b454d040ce5
Windows兼容性更好,蝙蝠或vbs最好.
从互联网上的任何地方,我将失去与家庭网络的连接.从工作开始我已经开始ping了,当它掉线时我已经完成了一个traceroute,它在它到达我的IP之前就失败了.
我需要一个日志文件来证明它不是我的调制解调器,路由器或计算机.
@echo off
set Address=google.com
:Loop
PING -n 5 127.0.0.1>nul
echo Pinging %Address%
%SystemRoot%\system32\ping.exe -n 1 %Address% | %SystemRoot%\system32\find.exe "TTL=" > NUL >> C:\pingtest\logfile.log
if %ERRORLEVEL% EQU 0 goto :Loop
echo Trace route %Address% at %date% %time% >> C:\pingtest\logfile.log
tracert %Address% >> C:\pingtest\logfile.log
goto Loop
Run Code Online (Sandbox Code Playgroud)
这就是我最终的目标,如果有其他人需要这个.基本上,"Ping -n 127.0.0.1> Nul"是添加一个5秒钟的计数器,这样它每5秒钟只能ping目的地,5可以改为任何需要的值.
Windows 7有这样的问题,ping可能导致类似"从192.168.1.5回复:目标主机无法访问".所以不是错误输出而是从自身获得回复而不是错误级别1.我没有查找错误级别1而是选择查找没有结果的TTL"%SystemRoot%\ system32\ping.exe -n 1%Address %|%SystemRoot%\ system32\find.exe"TTL ="> NUL"
无论如何,我确定这里的其他答案非常相似并且可能有效,所以我对它们进行排名,但将其标记为答案.
谢谢大家!
@echo off
set Address=www.google.com
set LogDir=C:\pingtest
md %LogDir%
%SystemRoot%\explorer.exe "%LogDir%"
echo PingTest script to monitor network connection. Control-C to exit.
echo Tests connection by pinging %Address%. Logs to %LogDir%\logfile.log.
echo %date% %time% Initial tracert (trace route) to %Address% >> %LogDir%\logfile.log
tracert %Address% >> %LogDir%\logfile.log
:Loop
REM 5 second delay
PING -n 5 -w 1 127.0.0.1>nul
echo %date% %time% Pinging %Address%
echo %date% %time% Pinging %Address% >> %LogDir%\logfile.log
%SystemRoot%\system32\ping.exe -n 1 %Address% | %SystemRoot%\system32\find.exe "TTL=" > NUL
if %ERRORLEVEL% EQU 0 goto :Loop
echo %date% %time% PING ERROR - Tracing route to %Address%
echo %date% %time% PING ERROR - Tracing route to %Address% >> %LogDir%\logfile.log
tracert %Address% >> %LogDir%\logfile.log
goto Loop
Run Code Online (Sandbox Code Playgroud)