titopluto / aioping

Python asyncio ping library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aioping is a fast asyncio implementation of ICMP (ping) protocol.

Installation

aioping requires Python 3.5.

Use pip to install it from the PyPI:

$ pip install aioping

Or use the latest version from the master (if you are brave enough):

$ pip install git+https://github.com/stellarbit/aioping

Using aioping

There are 2 ways to use the library.

First one is interactive, which prints results to the stdout. Please make sure you are running this code under root, as only root is allowed to send ICMP packets:

import asyncio
import aioping

loop = asyncio.get_event_loop()
loop.run_until_complete(aioping.verbose_ping("google.com"))

Alternatively, you can call a ping function, which returns a ping delay in milliseconds or throws an exception in case of error:

import asyncio
import aioping

async def do_ping(host):
    try:
        delay = await aioping.ping(host) * 1000
        print("Ping response in %s ms" % delay)

    except TimeoutError:
        print("Timed out")

loop = asyncio.get_event_loop()
loop.run_until_complete(do_ping("google.com"))

Credits

License

aioping is licensed under GPLv2.

About

Python asyncio ping library

License:GNU General Public License v2.0


Languages

Language:Python 100.0%