Coder Social home page Coder Social logo

aioping's Introduction

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 sends results to standard Python logger. Please make sure you are running this code under root, as only root is allowed to send ICMP packets:

import asyncio
import aioping
import logging

logging.basicConfig(level=logging.INFO)     # or logging.DEBUG
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"))

Methods

ping(dest_addr, timeout=10, family=None)

  • dest_addr - destination address, IPv4, IPv6 or hostname
  • timeout - timeout in seconds (default: 10)
  • family - family of resolved address - socket.AddressFamily.AF_INET for IPv4, socket.AddressFamily.AF_INET6 for IPv6 or None if it doesn't matter (default: None)

verbose_ping(dest_addr, timeout=2, count=3, family=None)

  • dest_addr - destination address, IPv4, IPv6 or hostname
  • timeout - timeout in seconds (default: 2)
  • count - count of packets to send (default: 3)
  • family - family of resolved address - socket.AddressFamily.AF_INET for IPv4, socket.AddressFamily.AF_INET6 for IPv6 or None if it doesn't matter (default: None)

Credits

License

aioping is licensed under GPLv2.

aioping's People

Contributors

anton-belousov avatar asantoni avatar crypto-spartan avatar harriv avatar hergla avatar samuel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.