Solved

Ping IP - Montoring Script cmd

Posted on 2006-11-14
6
8,189 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
6 Comments
 
LVL 18

Expert Comment

by:simsjrg
Comment Utility
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
"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
Comment Utility
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
Comment Utility
ok thanks guys =)
i'll keep using this until I see any issues.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now