简单的ping实施 [英] Simple ping implementation
问题描述
我需要简单的ping操作,如果目标不可达,它将返回一些浮点数或无.我正在使用Python 3和Windows,并且不想使用标准输入法,因为我必须从shell解码字节并解析结果.我对ICMP协议的实现一无所知,因此准备使用库是最好的选择.
I need simple ping that will return some float number or None if destination unreachable. I am using Python 3 and windows and don't want to use standart ping, cause i have to decode bytes from shell and parse results. I know nothing about implementation of ICMP protocol so ready to use library is the best choice.
推荐答案
您可以使用如下所示的纯Python实现:
You could use a pure Python implementation like the following:
https://pypi.python.org/pypi/ping
或者,如果您更喜欢这个:
or if you prefer this one:
http://www.python.org/~jeremy/python.html
并在这里看看,因为他们正在讨论该主题,您可能会发现它很有用:
and also take a look here, because they are discussing about the subject and you may find it useful:
更新
一个非常简单的示例,无需修补Py 3:
Without the need of patching for Py 3, a very simple example:
https://github.com/volftomas/pyicmp
这篇关于简单的ping实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!