使用windows icmp api的ping实现

winping的Python项目详细描述


winping

利用windows icmp api的ping实现

安装

标准python包安装。

用法

效用

概要
C:\>winping --help
usage: winping [-h] [-w TIMEOUT] [-l SIZE] [-t | -n COUNT] [-4 | -6] address

Ping implementation which utilizes Windows ICMP API

positional arguments:
  address     specifies the host name or IP address of the destination

optional arguments:
  -h, --help  show this help message and exit
  -w TIMEOUT  timeout in milliseconds to wait for each reply (default: 1000)
  -l SIZE     number of data bytes to be sent (default: 32)
  -t          ping the specified host until stopped (default: False)
  -n COUNT    number of echo requests to send (default: 4)
  -4          force using IPv4 (default: False)
  -6          force using IPv6 (default: False)

示例

C:\>winping google.com

Pinging google.com [172.217.20.206] with 32 bytes of data:
Reply from 172.217.20.206: bytes=32 time=29ms TTL=57
Reply from 172.217.20.206: bytes=32 time=25ms TTL=57
Reply from 172.217.20.206: bytes=32 time=24ms TTL=57
Reply from 172.217.20.206: bytes=32 time=25ms TTL=57

Ping statistics for 172.217.20.206:
    Packets: Sent = 4, Received = 4, Lost = 0 (0.00% loss),
Approximate round trip times in milli-seconds:
    Minimum = 24ms, Maximum = 29ms, Average = 26ms

C:\>winping -6 google.com

Pinging google.com [2a00:1450:401b:804::200e] with 32 bytes of data:
Reply from 2a00:1450:401b:804::200e: time=79ms
Reply from 2a00:1450:401b:804::200e: time=77ms
Reply from 2a00:1450:401b:804::200e: time=76ms
Reply from 2a00:1450:401b:804::200e: time=75ms

Ping statistics for 2a00:1450:401b:804::200e:
    Packets: Sent = 4, Received = 4, Lost = 0 (0.00% loss),
Approximate round trip times in milli-seconds:
    Minimum = 75ms, Maximum = 79ms, Average = 77ms

另外,如果python脚本不在系统路径中,则可以如下方式运行它:python -m winping

importwinpingwithwinping.IcmpHandle()ash:resp=winping.ping(h,'8.8.8.8')print(resp[0].RoundTripTime)withwinping.Icmp6Handle()ash:resp=winping.ping6(h,'2a00:1450:401b:804::200e')print(resp[0].RoundTripTime)

有关ping实用程序的工作示例,请参见winping/__main__.py

限制

  • 仅适用于Windows XP/Windows Server 2003及更高版本。
  • 目前不支持异步,但可以在线程执行器中运行ping。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从Struts操作的钩子更改表单值(Liferay 6.2)   java如何改变Spring MVC处理url“点”字符的行为   Clojure中使用Java接口的问题   junit如何模拟comosDB azure java集成客户端?   运行函数时发生java错误   netbeans Java。jar文件和依赖项   Eclipse中文本字段中的java输入类型   在JAVA中,将集合变量从实时批处理运行时传递到调用批处理文件   java通过Bean验证API中的自定义消息管理异常   XML到json的转换,在Java中,同时保留数据类型   根据JAVA中的列名从Excel文件中获取单元格值   在AsyncTask的doInBackground中未调用java FirebaseMessagingService   java如何在数据库中插入一行?