Solved

Ping Script & automatic trace route

Posted on 2011-02-16
8
798 Views
Last Modified: 2013-12-07
Hi,

I have a number of devices that loose connectivity, they are connected through various ways and 3rd party clouds. The connections drop at random times and i do not have the time to monitor them all and initiate a trace route once i discover one down.

I would like to write a ping script that will ping a selection of devices every 10 seconds or so and if the ping fails to initiate a trace route to the device.
I also need the outputs to be logged to a txt file.

Thanks,
0
Comment
Question by:-P-Henderson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 34914208
Looks like someone allready made that:
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_22882736.html

I hope it helps you as well.
0
 

Author Comment

by:-P-Henderson
ID: 34932507
I'm new to this kind of thing and to be honest the whole script doesn't make much sense,
0
 

Author Comment

by:-P-Henderson
ID: 34932517
-do i need to create a pinglog.txt if so, where does it need to be.
-where does the script source its IP's to ping, i have a range of 15 to ping if possible.
0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
LVL 35

Expert Comment

by:Ernie Beek
ID: 34933517
ok.

At the moment I have some leakage problems at home so I'm a bit busy right now :-~

I'll have a look as soon as I am able to.
0
 

Author Comment

by:-P-Henderson
ID: 34935758
Leakage,,,, not good.
I've go the ping script working with one Destination IP, just need to know how to get it to work with multiple ip's.
0
 
LVL 35

Accepted Solution

by:
Ernie Beek earned 500 total points
ID: 34938837
Right, I have dry feet again :)

So back to business. I made some changes to the original script:

 
@ECHO OFF

:VARIABLES

:: **************************************************************
:: * SET VARIABLES                                              *
:: **************************************************************

:: Retrieves a useable date from the system date.
SET yymmdd=%DATE:~8,2%-%DATE:~3,2%-%DATE:~0,2%

:: Change the below variable to desired target name or IP Address.
SET Machine=%1

:: Sets the logfile names and adds date stamp.
SET pinglog=pinglog_%yymmdd%
SET tracelog=tracelog_%yymmdd%

:: Sets the pingcount variable to zero.
SET pingcount=0

:PING

:: **************************************************************
:: * PING ROUTINE: Continuous loop to ping the machine name     *
:: * and write the results of the ping to the pinglog file.     *
:: * If ping fails to communicate with the server the loop will *
:: * exit and move on to the TRACE ROUTINE.                     *
:: **************************************************************

IF EXIST %TEMP%\temp.txt DEL %TEMP%\temp.txt

:: Displays status information on screen.
ECHO.
  ECHO Please wait, pinging %Machine%
ECHO.

:: Performs ping command on the target machine and outputs the
:: results to the pinglog file. If ping fails then will skip
:: to TRACE routine.

ping -w 1000 -n 4 %Machine% >>%TEMP%\temp.txt

for /f "tokens=1,* delims=," %%a in ('type %TEMP%\temp.txt ^| findstr /i "Request timed out"') do GOTO TRACE

  type %TEMP%\temp.txt
  
:: Writes completion message to the pinglog file.
ECHO. >>%pinglog%.txt
  ECHO ========================================================= >>%pinglog%.txt
  ECHO Ping Completed Succesfully at %TIME%                      >>%pinglog%.txt
  ECHO ========================================================= >>%pinglog%.txt
ECHO. >>%pinglog%.txt

:: Displays completion message on the screen.
ECHO.
  ECHO =========================================================
  ECHO Ping Completed Succesfully at %TIME%
  ECHO =========================================================
ECHO.
  
GOTO EOF

:TRACE

:: **************************************************************
:: * TRACE ROUTINE: Will perform a trace route command on the   *
:: * target machine and write the results to the tracelog file. *
:: * Once the trace has completed the routine will exit and go  *
:: * back to executing the PING ROUTINE.                        *
:: **************************************************************

IF EXIST %TEMP%\temp2.txt DEL %TEMP%\temp2.txt

type %TEMP%\temp.txt >>%pinglog%.txt

:: Writes ping failure message to the pinglog file.
ECHO. >>%pinglog%.txt
  ECHO ********************************************************* >>%pinglog%.txt
  ECHO Ping failed at %TIME% executing Trace Route.              >>%pinglog%.txt
  ECHO ********************************************************* >>%pinglog%.txt
ECHO. >>%pinglog%.txt

:: Writes ping failure message to the tracelog file.
ECHO. >>%tracelog%.txt
  ECHO ========================================================= >>%tracelog%.txt
  ECHO %Machine% did not respond at %TIME%                       >>%tracelog%.txt
  ECHO ========================================================= >>%tracelog%.txt

:: Displays ping failure message on the screen.
ECHO.
  ECHO =========================================================
  ECHO %Machine% did not respond at %TIME% 
  ECHO =========================================================
ECHO.

  ECHO Please wait, trace route is processing...

ECHO.
  
:: Performs Trace Route command on the target machine and writes
:: results to the tracelog file.
::   TRACERT %machine% >>%tracelog%.txt
     TRACERT %Machine% >>%TEMP%\temp2.txt
     
     type %TEMP%\temp2.txt >>%tracelog%.txt
     
:: Writes trace route completion message to the tracelog file.
ECHO. >>%tracelog%.txt
  ECHO Trace Route Completed at %TIME% on %DATE%. >>%tracelog%.txt
ECHO. >>%tracelog%.txt  

ECHO.
  ECHO Trace Route Completed at %TIME%
ECHO.

GOTO EOF

:EOF

EXIT /B

Open in new window


And called this one pping.bat

Then I created another little script:

 
@ECHO OFF
:DOPING
for /f %%z in (myhosts.txt) do call pping.bat %%z
GOTO DOPING

Open in new window


And called that runpping.bat

Third I made a txt file:
 myhosts.txt
In which you can put the ip adresses to be pinged.

Put this all together in a directory and run runpping.bat This will continue to run until CTRL-C is pressed.

Have a look to see if this is workable for you.
0
 

Author Closing Comment

by:-P-Henderson
ID: 35060020
My appologies for the delay, this worked a treat.... Thanks
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 35060040
Never mind, glad it's working.

And thx for the points :)
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many network operators, engineers, and administrators do not take several factors into consideration when troubleshooting network throughput and latency issues.  They often  measure the throughput by performing a measurement  by transferring a large…
Quality of Service (QoS) options are nearly endless when it comes to networks today. This article is merely one example of how it can be handled in a hub-n-spoke design using a 3-tier configuration.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question