Solved

Ping IP - Montoring Script cmd

Posted on 2006-11-14
6
8,229 Views
Last Modified: 2013-11-18
Hey Experts -
I am trying to create a script that will continuously ping several IP addresses listed in a text file. I have found a script that worked and tried modifying it so it would continue to ping at certain intervals, however I don't think I have the code right. I want it to ping say.. every 5 minutes or something to that effect - not every second. Also I think my loop is wrong as it is only pinging the first IP in my textfile and not the others. (It works fine however when I modify it for a one time ping.) Can someone take a look at this and help?
This is my first time really scripting something like this.. but I had thought that the -W part meant the pause between pings - but it didn't seem to slow down one bit. If anyone could help explain the -N and -W it would really help.
Note: I don't want to use outside resources as it would mean me having to jump thru hoops to get software approved and all that - for security and simplicity issues - scripting is my best option.
Could anyone also tell me if this method would effect the performance of the server or my machine?
Thanks

@echo off

if exist error.txt del error.txt >NUL

:pingtest

for /f "delims=" %%a in ('type myIP.TXT') do call :PROCESS %%a

goto :pingtest

:PROCESS

ping %1 -n 1 -w 20000 >NUL

if ERRORLEVEL 1 goto IPERROR

echo IP: %1 worked  
goto :pingtest

:IPERROR

echo IP: %1 is down at %time% >> error.txt
0
Comment
Question by:ThinkPaper
[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
6 Comments
 
LVL 18

Expert Comment

by:simsjrg
ID: 17940447
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 17940458
Try this and post your results please...comments are posted first:

1- specify path of myIP.txt (don't need 'type')
2- ping localhost is an internal 'trick' to wait a approximate amount of seconds
3- removed your goto :pingtest inside of process -unneeded


@echo off
if exist error.txt del error.txt >NUL
:pingtest
for /f "delims=" %%a in (c:\folder\myIP.txt) do call :PROCESS %%a
::wait 300 seconds before continuing
ping localhost -n 300 > NUL
goto :pingtest

:PROCESS
ping %1 -n 1 >NUL
if ERRORLEVEL 1 goto IPERROR
echo IP: %1 worked  
goto :eof

:IPERROR
echo IP: %1 is down at %time% >> error.txt
0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 17940917
Thanks for the quick response. It works great. I modified it a little bit to output on command line when it failed.

So on the command line it only printed when it couldn't ping an IP. And any errors went into the error.txt

A couple questions - any reason why this method would not be a good idea? I'm wondering if I would be pinging the server too much or taking up too much resources or whatever. (I'm not a network person - I'm just helping someone automate this task for them.)

And is there a better way of doing this (like making an alert box pop up when an IP fails)?

Thanks!
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 67

Expert Comment

by:sirbounty
ID: 17941065
"any reason why this method would not be a good idea? "

Hmm - I'd say likely not, but keep an eye on it, just in case...  If things start to degrade, you'll know soon enough.
The pinging localhost (the loopback) doesn't 'go' anywhere, so that's not even on your network.  It may take a minute amount of local resources, but it's unlikely to cause any problem.  Now depending on your operating system and/or availability to download free tools, there is a utility called sleep (just type sleep at the command prompt to see if you have it already) that essentially pauses execution for you.  It's probably not any more/less of a resource usage problem, it just 'looks' cleaner when using it.

"And is there a better way of doing this (like making an alert box pop up when an IP fails)?"

There are several monitoring tools out there...snmp traps, tivoli, netview, etc that serve a similar purpose (with added support features).  
0
 
LVL 7

Expert Comment

by:dlangr
ID: 17941143
don't forget:

bigsister http://www.bigsister.ch/bigsister.html (free, runs on windows, linux and probably others)
bigbrother http://www.bb4.org/ (a free and a commercial version)


0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 17941363
ok thanks guys =)
i'll keep using this until I see any issues.
0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

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