Script to run traceroute if continuous ping fails, logging

I want to constantly ping my home IP address, and if ping fails to automatically make traceroute to see where it does not work.

I tried to follow the comments made here:

http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/efc97c66-60a6-4fd7-8be4-4b454d040ce5

Compatibility with Windows would be preferable, it would be better to use bat or vbs.

From anywhere on the Internet I will lose connection to my home network. From work, I started ping, and when it fell, I did a traceroute, and it fails before it gets to my IP.

I need a log file to prove that it is not my modem, router or computer.

+5
source share
5 answers
@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

This is what I came across if someone else needs it. Essentially, “Ping -n 127.0.0.1> Nul” should add a 5 second counter so that it only pings the destination every 5 seconds, 5 could be changed to any value.

Windows 7 has this problem when ping can lead to something like "response from 192.168.1.5: Destination host unreachable". Therefore, instead of failing, it receives a response from itself, and not error level 1. Instead of searching for error level 1, I do not want to search for the result for TTL with "% SystemRoot% \ system32 \ ping.exe -n 1% Address% |% SystemRoot% \ system32 \ find.exe "TTL ="> NUL "

, , , , , , .

!

+6
@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
+2

, ping, , tracert, :

setlocal
set host=www.bigpond.com
set logfile=nettest.log
echo %date% %time%>>%logfile%
ping %host%>>%logfile%
if ERRORLEVEL 1 tracert %host%>>%logfile
endlocal

.

, .

"sleep". , :

choice /d y /t 5 > nul
+1
:LOOP
FOR /F "usebackq tokens=1" %%F IN (`ping localhost -n 1 -w 1 ^| find "Request"`) DO (
  IF "%%F"=="Request" (
    tracert localhost
  )
)>>log.txt
FOR /F "usebackq tokens=1-4 delims=:." %%G IN (`echo %time%`) DO IF %G%H GTR 1400 GOTO:EOF
GOTO LOOP

, ping, , Request ( , ping-) tracert. -n -w ping , 1 . , . FOR . 1400 , script ( , ).

+1

I just searched the same to investigate why the VPN keeps dropping on a wired connection, used one of the batch file suggestions, which was great above. Also found a nice little Java application that sends it to you here Internet connection monitor

Easy to use and does the job :-)

0
source

All Articles