Solved

Ping Script & automatic trace route

Posted on 2011-02-16
8
793 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
  • 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outdoor Wifi Radio with Splash Page 6 67
In what cases will server send empty session id during TLS handshake 3 101
does nexus 9k support nbar 5 90
Deny permission ACL 16 26
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…
When replacing some switches recently I started playing with the idea of having admins authenticate with their domain accounts instead of having local users on all switches all over the place. Since I allready had an w2k8R2 NPS running for my acc…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

809 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