使用PING测试IP地址

本文介绍了一个利用AutoHotkey脚本实现的功能,该脚本接收包含多个IP地址的文本文件,对每个IP地址执行PING命令。如果检测到如'目标主机不可达'等常见PING错误,脚本会通过SMTP发送错误通知邮件。适用于自动化网络监控和故障排查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

在这里专家交流。 楼主(OP)需要一个实用工具,将接受IP地址作为输入的列表,PING每个在列表中的IP地址,并通过SMTP当PING不成功上的IP地址发送电子邮件到一个支持小组。

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.

本文介绍的方法需要使用一种出色的(免费!)编程/脚本语言AutoHotkey 。 安装AutoHotkey的快速说明是访问其网站 ,然后单击蓝色的大下载按钮。 更全面的解释是阅读我的EE文章AutoHotkey-Getting Started 。 安装后,AutoHotkey将拥有AHK文件类型,支持本文其余部分讨论的解决方案。

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

该实用程序将纯文本文件作为输入,每个IP地址在单独的行中,例如:

192.168.0.123

192.168.0.123

192.168.0.456

192.168.0.456

192.168.0.789

192.168.0.789

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:

该实用程序读取包含IP地址和PING列表的文件。 它将PING命令的输出重定向到文本文件(通过命令行“ > ”运算符)。 然后,它会在PING输出中的任何位置查找五个最常见的PING错误,即:

Destination Host Unreachable

目标主机不可达

Ping request could not find host

ping请求找不到主机

Request Timed Out

请求超时

TTL Expired in Transit

TTL在运输中过期

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:

如果公用程序发现任何这些,它通过SMTP发送一封电子邮件,PING错误通知主体 ,与电子邮件正文 ,看起来像这样:

IP Address: 192.168.0.123

IP地址:192.168.0.123

PING output: Reply from 192.168.0.101: Destination host unreachable.

PING输出:来自192.168.0.101的回复:无法访问目标主机。

Another example of what it may look like is this:

另一个示例如下所示:

IP Address: 192.168.0.456

IP地址:192.168.0.456

PING output: Request timed out.

PING输出:请求超时。

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).

该脚本作为名为PING_IP_Addresses.ahk的文件附加到本文(重要说明:我更新了该文章,因此该文章附带的文件比“注释”中发布的版本晚)。 我使用Gmail.com作为SMTP服务器(及其必需的参数)对其进行了测试,但这很容易更改。 需要修改的六行代码(用于文件名,SMTP服务器和电子邮件参数)中的每一行都从第60列开始标记为“ ; *** ”(如果未使用SMTP服务器,则需要更改其他行) 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.

下载脚本并用您的信息对其进行修改后,只需在Windows / File Explorer(或您使用的任何文件管理器)中双击该脚本即可运行它。 由于其文件类型为AHK,因此将启动AutoHotkey进行处理。 如果您愿意,可以通过AutoHotkey编译器将文件转换为可执行文件(EXE文件),如我的AutoHotkey-入门文章中所述。

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

运行脚本时,它将在对话框中显示绿色进度条,该对话框显示了它处理的每个IP地址:

Progress-Bar.jpg

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

完成百分比基于列表中IP地址的数量。

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.

重要的是要注意,该实用程序将不会检测到除最常见的五个错误(如上所述)之外的PING错误。 有了这一警告,我希望该实用程序对OP和其他EE成员有用。

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

如果您发现本文有帮助,请单击下面的大拇指图标。 这使我知道什么对EE成员有价值,并为以后的文章提供了指导。 非常感谢! 问候乔

PING-IP-Addresses.ahk PING-IP-Addresses.ahk

翻译自: https://www.experts-exchange.com/articles/12272/Test-IP-Addresses-with-PING.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值