Test IP Addresses with PING

Published on
21,950 Points
5 Endorsements
Last Modified:
Joe Winograd
50+ years in computer industry
CIO•Document Imaging
EE — FELLOW 2017
MVE 2015,2016,2018
RENOWNED 2018,2019
GOLD 2020
This article is in response to a question here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses as input, PING each of the IP addresses in the list, and send an email via SMTP to a support group when the PING is not successful on an IP address.

The method presented in this article requires AutoHotkey, an excellent (free!) programming/scripting language. The quick explanation for installing AutoHotkey is to visit its website and click the big blue Download button. A more comprehensive explanation is to read my EE article, AutoHotkey - Getting Started. After installation, AutoHotkey will own the AHK file type, supporting the solution discussed in the remainder of this article.

The utility takes as input a plain text file with each IP address on a separate line, such as:

The utility reads the file with the list of IP addresses and PINGs each one. It redirects the output of the PING command to a text file (via the command line ">" operator). It then looks for the five most common PING errors anywhere in the PING output, namely:

Destination Host Unreachable
Ping request could not find host
Request Timed Out
TTL Expired in Transit
Unknown Host

If the utility finds any of these, it sends an email via SMTP with PING Error Notification as the Subject and with an email Body that looks like this:

IP Address:
PING output: Reply from Destination host unreachable.

Another example of what it may look like is this:

IP Address:
PING output: Request timed out.

Of course, you may modify the script to change the Subject and Body of the email as desired.

The script is attached to this article as a file called PING_IP_Addresses.ahk (Important Note: I updated the article so the file attached to the article is later than the version posted in the Comments). I tested it with Gmail.com as the SMTP server (along with its required parameters), but this may be easily changed. Each of the six lines of code that needs modification (for your file names, SMTP server, and email parameters) is marked with ";***" beginning in column 60 (other lines will need to be changed if your SMTP server is not Gmail).

After downloading the script and modifying it with your information, you may run it by simply double-clicking on it in Windows/File Explorer (or whatever file manager you use). Since its file type is AHK, AutoHotkey will be launched to process it. If you prefer, the file may be turned into an executable (an EXE file) via the AutoHotkey compiler, as explained in my AutoHotkey - Getting Started article.

When running the script, it displays a green progress bar in a dialog box that shows each IP address that it processes:

The percentage Done is based on the number of IP addresses in the list.

It is important to note that PING errors other than the most common five (as documented above) will not be detected by this utility. With that caveat, I hope that the utility is useful to the OP and other EE members.

If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe

Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free