Giter Club home page Giter Club logo

aioping's Introduction

aioping

An asyncio-based python ping implementation using raw sockets.

  • Compatible with Python 3.5 ff.
  • Note that ICMP messages can only be sent from processes running as root (in Windows, you must run this script as 'Administrator').

Original Version

  • Matthew Dixon Cowles
  • copyleft 1989-2016 by the python-ping team, see AUTHORS for more details.
  • license: GNU GPL v2, see LICENSE for more details.

Usage

usage: ping [-h] [-w TIMEOUT] [-c COUNT] [-i INTERVAL] [-4] [-6]
            [-I SOURCEINTF] [-s NUMDATABYTES] [-T] [-S SOURCEIP]
            hostname

A pure python implementation of the ping protocol. *REQUIRES ROOT*

positional arguments:
  hostname              The address to attempt to ping.

optional arguments:
  -h, --help            show this help message and exit
  -w TIMEOUT, --deadline TIMEOUT
                        The maximum amount of time to wait until ping times
                        out.
  -c COUNT, --request_count COUNT
                        The number of attempts to make. Zero=infinite.
  -i INTERVAL, --interval INTERVAL
                        Time between ping attempts
  -4, --ipv4            Flag to use IPv4.
  -6, --ipv6            Flag to use IPv6.
  -I SOURCEINTF, --interface SOURCEINTF
                        Interface to use.
  -s NUMDATABYTES, --packet_size NUMDATABYTES
                        Designate the amount of data to send per packet.
  -T, --test_case       Flag to run the default test case suite.
  -S SOURCEIP, --source_address SOURCEIP
                        Source address from which ICMP Echo packets will be
                        sent.

Using as lib

# python3
>>> from aioping import ping
>>> ping('google.com', timeout=3000, count=3, delay=0.5)
True
>>> ping('google.com', timeout=3000, count=3, delay=0.5, verbose=True)

PYTHON PING google.com (216.58.212.46): 1300 data bytes
72 bytes from 216.58.212.46: icmp_seq=0 ttl=59 time=4.42 ms
72 bytes from 216.58.212.46: icmp_seq=1 ttl=59 time=4.70 ms
72 bytes from 216.58.212.46: icmp_seq=2 ttl=59 time=4.44 ms
72 bytes from 216.58.212.46: icmp_seq=3 ttl=59 time=4.47 ms

----216.58.212.46 PYTHON PING Statistics----
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip (ms)  min/avg/max = 4.4/4.5/4.7

1

Async usage is via the {Ping} class, which can be used like this:

from aioping import Ping,VerbosePing
async def ping(hostname, verbose=True, handle_signals=False, **kw):
    """
    Send @count ping to @hostname with the given @timeout
    """
    ping = (VerbosePing if verbose else Ping)(verbose=verbose, **kw)
    if handle_signals: ping.add_signal_handler()
    await ping.init(hostname)
    res = await ping.looped()
    if verbose:
        ping.print_stats()
    ping.close()
    return res

contribute

Fork this repo on GitHub and send pull requests. Thank you.

Revision history

Revision history

Links

Sourcecode at GitHub https://github.com/M-o-a-T/aioping

aioping's People

Contributors

bstevant avatar eclectickmedia avatar estemendoza avatar fliegendewurst avatar insekt avatar jedie avatar l4m3rx avatar pepoluan avatar pferate avatar rafaga avatar samuel avatar simudream avatar smurfix avatar techwizrd avatar

Forkers

mrfoxyfoxy

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.