Downloads
102911.zip

The staff at a remote location in my company had reported frequent network outages, so I had to come up with a way to monitor their network connection. I wanted to see how often the connection went down and how long it took to come back up. Rather than spending money on a commercial program or digging through huge ping logs, I pulled together a few free utilities and wrote a .bat script named Pingmon.

Pingmon is simple in concept: It watches an address that's either responding or not, and if the state changes, the script generates an email and a log entry. The log shows when the connection went up or down. When a connection goes from down to up, the log also shows how long it was down.

The syntax to use Pingmon is straightforward:

pingmon
  \[\]

where

  • computername is the name or IP address of the device you want to monitor
  • frequency is the number of seconds to wait between ping attempts
  • email-address is where you want to receive email notifications
  • log-file is the name of the file in which you want to log all state changes
  • comment is an optional one-word description of what you're monitoring

(Although this command wraps here, you'd enter it all on one line. The same holds true for the sample command that follows.)

If you don't want to receive the email notifications or have a log file, you can just use a period for that parameter. You might not want email notifications if you expect a device to go up and down frequently and you just need to keep track of the device's state. You might not want to have a log file if you need to take some action as soon as a device becomes available.

Pingmon uses three utilities: date.exe, SleepX, and Blat. Date.exe is a port of the UNIX date command. It provides a UNIX-type date so that the script can calculate how long a circuit is down. Date.exe is one of many UNIX tools in the UnxUtils.zip file, which you can download from unxutils.sourceforge.net.

The script uses SleepX to create a pause between ping attempts. SleepX is part of the Shell Scripting Toolkit, which is collection of Win32 command-line utilities you can use in cmd.exe shell scripts. You can download the Shell Scripting Toolkit from www.westmesatech.com/sst.html.

Pingmon uses Blat to send the email notifications. Blat is an extremely versatile command-line mailer that's easy to set up and use. However, I recommend that you install it as follows: Download the utility from www.blat.net, and copy the blat.exe file into a library in your path. Then, at a command prompt, run

blat.exe –install
 

substituting your.mailserver.com and you@yourdomain.com with the name of your SMTP email server and your email address, respectively. Installing it this way saves these values in your registry so you don't have to pass them as parameters every time you run Blat.

Besides using Pingmon to troubleshoot the remote location's network outages, my colleagues and I have found many other uses for it. We've used it to watch several devices at remote locations to determine what switches are dropping out. To monitor a plant's network, we ran several Pingmon scripts, had them log to the same file, and set up a scheduled task to email the log to us every day. We also used the script to monitor servers awaiting reboots and monitor circuit uptime in international locations. Whatever you're watching, Pingmon throws out the fluff so you only have to look at interesting events.

You can download Pingmon, which I wrote for use on Windows NT 4.0 and later, by clicking the Download the Code Here button. You don't need to customize the code at all, but you do need to install the date.exe, SleepX, and Blat utilities to use Pingmon. Depending on what you plan to use Pingmon for, you might want to enhance it. For example, you could add an option to write the log entries in a database or have it run Traceroute (tracert.exe) when a device goes down.