pingparsing


Namepingparsing JSON
Version 1.4.2 PyPI version JSON
download
home_pagehttps://github.com/thombashi/pingparsing
Summarypingparsing is a CLI-tool/Python-library parser and transmitter for the ping command.
upload_time2024-05-02 09:34:55
maintainerNone
docs_urlNone
authorTsuyoshi Hombashi
requires_python>=3.7
licenseMIT License
keywords cli library network ping parser transmitter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. contents:: **pingparsing**
   :backlinks: top
   :depth: 2

Summary
=========
`pingparsing <https://github.com/thombashi/pingparsing>`__ is a CLI-tool/Python-library parser and transmitter for the ping command.

|PyPI pkg ver| |Supported Python impl| |Supported Python ver| |CI status| |CodeQL|

.. |PyPI pkg ver| image:: https://badge.fury.io/py/pingparsing.svg
    :target: https://badge.fury.io/py/pingparsing
    :alt: PyPI package version

.. |Supported Python impl| image:: https://img.shields.io/pypi/implementation/pingparsing.svg
    :target: https://pypi.org/project/pingparsing
    :alt: Supported Python implementations

.. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/pingparsing.svg
    :target: https://pypi.org/project/pingparsing
    :alt: Supported Python versions

.. |CI status| image:: https://github.com/thombashi/pingparsing/actions/workflows/ci.yml/badge.svg
    :target: https://github.com/thombashi/pingparsing/actions/workflows/ci.yml
    :alt: CI status of Linux/macOS/Windows

.. |CodeQL| image:: https://github.com/thombashi/pingparsing/actions/workflows/github-code-scanning/codeql/badge.svg
    :target: https://github.com/thombashi/pingparsing/actions/workflows/github-code-scanning/codeql
    :alt: CodeQL

CLI Usage
====================
A CLI command (``pingparsing`` command) is included in the package. The command could do the following:

- Execute ``ping`` and parse the result
- Parse ping results from:
    - file(s)
    - the standard input

Execute ping and parse the result
--------------------------------------------
If you specify destination(s) to the ``pingparsing`` command as positional arguments,
the command executes ``ping`` for each destination(s) and parses the result.
``ping`` will execute in parallel for multiple destinations.
The parsed result is outputted in JSON format.

.. code-block:: console

    $ pingparsing google.com
    {
        "google.com": {
            "destination": "google.com",
            "packet_transmit": 10,
            "packet_receive": 10,
            "packet_loss_rate": 0.0,
            "packet_loss_count": 0,
            "rtt_min": 34.189,
            "rtt_avg": 46.054,
            "rtt_max": 63.246,
            "rtt_mdev": 9.122,
            "packet_duplicate_rate": 0.0,
            "packet_duplicate_count": 0
        }
    }

.. code-block:: console

    $ pingparsing google.com twitter.com
    {
        "google.com": {
            "destination": "google.com",
            "packet_transmit": 10,
            "packet_receive": 10,
            "packet_loss_rate": 0.0,
            "packet_loss_count": 0,
            "rtt_min": 37.341,
            "rtt_avg": 44.538,
            "rtt_max": 53.997,
            "rtt_mdev": 5.827,
            "packet_duplicate_rate": 0.0,
            "packet_duplicate_count": 0
        },
        "twitter.com": {
            "destination": "twitter.com",
            "packet_transmit": 10,
            "packet_receive": 10,
            "packet_loss_rate": 0.0,
            "packet_loss_count": 0,
            "rtt_min": 45.377,
            "rtt_avg": 68.819,
            "rtt_max": 78.581,
            "rtt_mdev": 9.769,
            "packet_duplicate_rate": 0.0,
            "packet_duplicate_count": 0
        }
    }

.. code-block:: console

    $ pingparsing google.com -c 3 --icmp-reply
    {
        "google.com": {
            "destination": "google.com",
            "packet_transmit": 3,
            "packet_receive": 3,
            "packet_loss_count": 0,
            "packet_loss_rate": 0.0,
            "rtt_min": 36.997,
            "rtt_avg": 49.1,
            "rtt_max": 60.288,
            "rtt_mdev": 9.533,
            "packet_duplicate_count": 0,
            "packet_duplicate_rate": 0.0,
            "icmp_replies": [
                {
                    "destination": "nrt20s21-in-f14.1e100.net (172.217.175.110)",
                    "bytes": 64,
                    "icmp_seq": 1,
                    "ttl": 113,
                    "time": 50.0,
                    "duplicate": false
                },
                {
                    "destination": "nrt20s21-in-f14.1e100.net (172.217.175.110)",
                    "bytes": 64,
                    "icmp_seq": 2,
                    "ttl": 113,
                    "time": 60.2,
                    "duplicate": false
                },
                {
                    "destination": "nrt20s21-in-f14.1e100.net (172.217.175.110)",
                    "bytes": 64,
                    "icmp_seq": 3,
                    "ttl": 113,
                    "time": 36.9,
                    "duplicate": false
                }
            ]
        }
    }


Parse ping result file
--------------------------------------------
:Input:
    .. code-block:: console

        $ cat ping.txt
        PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.

        --- 192.168.0.1 ping statistics ---
        1688 packets transmitted, 1553 received, +1 duplicates, 7% packet loss, time 2987ms
        rtt min/avg/max/mdev = 0.282/0.642/11.699/0.699 ms, pipe 2, ipg/ewma 1.770/0.782 ms
        $ cat osx.txt
        PING google.com (172.217.6.238): 56 data bytes
        64 bytes from 172.217.6.238: icmp_seq=0 ttl=53 time=20.482 ms
        64 bytes from 172.217.6.238: icmp_seq=1 ttl=53 time=32.550 ms
        64 bytes from 172.217.6.238: icmp_seq=2 ttl=53 time=32.013 ms
        64 bytes from 172.217.6.238: icmp_seq=3 ttl=53 time=28.498 ms
        64 bytes from 172.217.6.238: icmp_seq=4 ttl=53 time=46.093 ms

        --- google.com ping statistics ---
        5 packets transmitted, 5 packets received, 0.0% packet loss
        round-trip min/avg/max/stddev = 20.482/31.927/46.093/8.292 ms

:Output:
    .. code-block:: console

        $ pingparsing ping.txt osx.txt
        {
            "osx.txt": {
                "destination": "google.com",
                "packet_transmit": 5,
                "packet_receive": 5,
                "packet_loss_rate": 0.0,
                "packet_loss_count": 0,
                "rtt_min": 20.482,
                "rtt_avg": 31.927,
                "rtt_max": 46.093,
                "rtt_mdev": 8.292,
                "packet_duplicate_rate": null,
                "packet_duplicate_count": null
            },
            "ping.txt": {
                "destination": "192.168.0.1",
                "packet_transmit": 1688,
                "packet_receive": 1553,
                "packet_loss_rate": 7.997630331753558,
                "packet_loss_count": 135,
                "rtt_min": 0.282,
                "rtt_avg": 0.642,
                "rtt_max": 11.699,
                "rtt_mdev": 0.699,
                "packet_duplicate_rate": 0.0643915003219575,
                "packet_duplicate_count": 1
            }
        }

    .. code-block:: console

        $ pingparsing ping.txt osx.txt --icmp-reply
        {
            "ping.txt": {
                "destination": "google.com",
                "packet_transmit": 60,
                "packet_receive": 60,
                "packet_loss_count": 0,
                "packet_loss_rate": 0.0,
                "rtt_min": 61.425,
                "rtt_avg": 99.731,
                "rtt_max": 212.597,
                "rtt_mdev": 27.566,
                "packet_duplicate_count": 0,
                "packet_duplicate_rate": 0.0,
                "icmp_replies": []
            },
            "osx.txt": {
                "destination": "google.com",
                "packet_transmit": 5,
                "packet_receive": 5,
                "packet_loss_count": 0,
                "packet_loss_rate": 0.0,
                "rtt_min": 20.482,
                "rtt_avg": 31.927,
                "rtt_max": 46.093,
                "rtt_mdev": 8.292,
                "packet_duplicate_count": 0,
                "packet_duplicate_rate": 0.0,
                "icmp_replies": [
                    {
                        "icmp_seq": 0,
                        "ttl": 53,
                        "time": 20.482,
                        "duplicate": false
                    },
                    {
                        "icmp_seq": 1,
                        "ttl": 53,
                        "time": 32.55,
                        "duplicate": false
                    },
                    {
                        "icmp_seq": 2,
                        "ttl": 53,
                        "time": 32.013,
                        "duplicate": false
                    },
                    {
                        "icmp_seq": 3,
                        "ttl": 53,
                        "time": 28.498,
                        "duplicate": false
                    },
                    {
                        "icmp_seq": 4,
                        "ttl": 53,
                        "time": 46.093,
                        "duplicate": false
                    }
                ]
            }
        }


Parse from the standard input
--------------------------------------------
.. code-block:: console

    $ ping -i 0.2 -w 20 192.168.2.101 | pingparsing -
    {
        "destination": "192.168.2.101",
        "packet_transmit": 99,
        "packet_receive": 88,
        "packet_loss_count": 11,
        "packet_loss_rate": 11.11111111111111,
        "rtt_min": 1.615,
        "rtt_avg": 26.581,
        "rtt_max": 93.989,
        "rtt_mdev": 19.886,
        "packet_duplicate_count": 0,
        "packet_duplicate_rate": 0.0
    }

CLI help
--------------------------------------------
::

    usage: pingparsing [-h] [-V] [--max-workers MAX_WORKERS]
                       [--timestamp {none,epoch,datetime}] [-c COUNT]
                       [-s PACKET_SIZE] [--ttl TTL] [-w DEADLINE]
                       [--timeout TIMEOUT] [-I INTERFACE] [--addopts OPTIONS]
                       [--indent INDENT] [--icmp-reply] [--timezone TIMEZONE]
                       [--no-color] [--debug | --quiet]
                       destination_or_file [destination_or_file ...]

    positional arguments:
      destination_or_file   Destinations to send ping or files to parse. '-' for
                            parsing the standard input.

    options:
      -h, --help            show this help message and exit
      -V, --version         show program's version number and exit
      --max-workers MAX_WORKERS
                            Number of threads for when multiple destinations/files
                            are specified. Defaults to equal two times the number
                            of cores.
      --debug               for debug print.
      --quiet               suppress execution log messages.

    Ping Options:
      --timestamp {none,epoch,datetime}
                            [Only for LINUX] none: no timestamps. epoch: add
                            timestamps with UNIX epoch time format. datetime: add
                            timestamps with ISO time format.
      -c COUNT, --count COUNT
                            Stop after sending the count. see also ping(8) [-c
                            count] option description.
      -s PACKET_SIZE, --packet-size PACKET_SIZE
                            Specifies the number of data bytes to be sent.
      --ttl TTL             Specifies the Time to Live.
      -w DEADLINE, --deadline DEADLINE
                            Timeout before ping exits. valid time units are:
                            d/day/days, h/hour/hours, m/min/mins/minute/minutes,
                            s/sec/secs/second/seconds,
                            ms/msec/msecs/millisecond/milliseconds,
                            us/usec/usecs/microsecond/microseconds. if no unit
                            string found, considered seconds as the time unit. see
                            also ping(8) [-w deadline] option description. note:
                            meaning of the 'deadline' may differ system from to
                            system.
      --timeout TIMEOUT     Time to wait for a response per packet. Valid time
                            units are: d/day/days, h/hour/hours,
                            m/min/mins/minute/minutes, s/sec/secs/second/seconds,
                            ms/msec/msecs/millisecond/milliseconds,
                            us/usec/usecs/microsecond/microseconds. If no unit
                            string is found, consider milliseconds as the time
                            unit. Attempt to send packets with milliseconds
                            granularity in default. If the system does not support
                            timeout in milliseconds, round up as seconds. Use
                            system default if not specified. This option will be
                            ignored if the system does not support timeout itself.
                            See also ping(8) [-W timeout] option description.
                            note: meaning of the 'timeout' may differ from system
                            to system.
      -I INTERFACE, --interface INTERFACE
                            network interface
      --addopts OPTIONS     extra command line options

    Output Options:
      --indent INDENT       JSON output will be pretty-printed with the indent
                            level. (default= 4)
      --icmp-reply, --icmp-replies
                            print results for each ICMP packet reply.
      --timezone TIMEZONE   Time zone for timestamps.
      --no-color            Turn off colors.

    Documentation: https://pingparsing.rtfd.io/
    Issue tracker: https://github.com/thombashi/pingparsing/issues

Library Usage
====================

Execute ping and parse the result
--------------------------------------------
``PingTransmitter`` class can execute ``ping`` command and obtain the
ping output as a string.

:Sample Code:
    .. code-block:: python

        import json
        import pingparsing

        ping_parser = pingparsing.PingParsing()
        transmitter = pingparsing.PingTransmitter()
        transmitter.destination = "google.com"
        transmitter.count = 10
        result = transmitter.ping()

        print(json.dumps(ping_parser.parse(result).as_dict(), indent=4))

:Output:
    .. code-block:: json

        {
            "destination": "google.com",
            "packet_transmit": 10,
            "packet_receive": 10,
            "packet_loss_rate": 0.0,
            "packet_loss_count": 0,
            "rtt_min": 34.458,
            "rtt_avg": 51.062,
            "rtt_max": 62.943,
            "rtt_mdev": 8.678,
            "packet_duplicate_rate": 0.0,
            "packet_duplicate_count": 0
        }


Parsing ``ping`` command output
-------------------------------
:Sample Code:
    .. code-block:: python

        import json
        from textwrap import dedent
        import pingparsing

        parser = pingparsing.PingParsing()
        stats = parser.parse(dedent("""\
            PING google.com (74.125.24.100) 56(84) bytes of data.
            [1524930937.003555] 64 bytes from 74.125.24.100: icmp_seq=1 ttl=39 time=148 ms
            [1524930937.787175] 64 bytes from 74.125.24.100: icmp_seq=2 ttl=39 time=137 ms
            [1524930938.787642] 64 bytes from 74.125.24.100: icmp_seq=3 ttl=39 time=137 ms
            [1524930939.787653] 64 bytes from 74.125.24.100: icmp_seq=4 ttl=39 time=136 ms
            [1524930940.788365] 64 bytes from 74.125.24.100: icmp_seq=5 ttl=39 time=136 ms

            --- google.com ping statistics ---
            5 packets transmitted, 5 received, 0% packet loss, time 4001ms
            rtt min/avg/max/mdev = 136.537/139.174/148.006/4.425 ms
            """))

        print("[extract ping statistics]")
        print(json.dumps(stats.as_dict(), indent=4))

        print("\n[extract icmp replies]")
        for icmp_reply in stats.icmp_replies:
            print(icmp_reply)

:Output:
    ::

        [ping statistics]
        {
            "destination": "google.com",
            "packet_transmit": 5,
            "packet_receive": 5,
            "packet_loss_count": 0,
            "packet_loss_rate": 0.0,
            "rtt_min": 136.537,
            "rtt_avg": 139.174,
            "rtt_max": 148.006,
            "rtt_mdev": 4.425,
            "packet_duplicate_count": 0,
            "packet_duplicate_rate": 0.0
        }

        [icmp replies]
        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 37, 3555), 'icmp_seq': 1, 'ttl': 39, 'time': 148.0, 'duplicate': False}
        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 37, 787175), 'icmp_seq': 2, 'ttl': 39, 'time': 137.0, 'duplicate': False}
        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 38, 787642), 'icmp_seq': 3, 'ttl': 39, 'time': 137.0, 'duplicate': False}
        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 39, 787653), 'icmp_seq': 4, 'ttl': 39, 'time': 136.0, 'duplicate': False}
        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 40, 788365), 'icmp_seq': 5, 'ttl': 39, 'time': 136.0, 'duplicate': False}


Recommended ping command execution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following methods are recommended to execute ``ping`` command to get the output for parsing.
These commands include an operation that changes the locale setting to English temporarily.

Linux
^^^^^
.. code:: console

    LC_ALL=C ping <host or IP address> -w <seconds> [option] > <output.file>

Windows
^^^^^^^
.. code:: console

    > chcp
    Active code page: <XXX>    # get current code page

    > chcp 437    # change code page to english
    > ping <host or IP address> -n <ping count> > <output.file>
    > chcp <XXX>    # restore code page

-  Reference
    - https://technet.microsoft.com/en-us/library/cc733037

Installation
============
::

    pip install pingparsing


Dependencies
============
- Python 3.7+
- `Python package dependencies (automatically installed) <https://github.com/thombashi/pingparsing/network/dependencies>`__

Optional Dependencies
------------------------------------
- pingparsing[cli] extras
    - `loguru <https://github.com/Delgan/loguru>`__
        - Used for logging if the package installed
    - `Pygments <http://pygments.org/>`__
        - Syntax highlighting to ``pingparsing`` command output when installed


Docker Image
==================
`thombashi/pingparsing - Docker Hub <https://hub.docker.com/r/thombashi/pingparsing/>`__

Supported Environments
============================
- Linux
- Windows
- macOS

Tested Environments
---------------------------

+--------------+-----------------------------------+
| OS           | ping version                      |
+==============+===================================+
| Ubuntu 16.04 | ``iputils-ping 20121221-5ubuntu2``|
+--------------+-----------------------------------+
| Ubuntu 18.04 | ``iputils-ping 20161105-1ubuntu2``|
+--------------+-----------------------------------+
| Ubuntu 20.04 | ``iputils-ping 20190709-3``       |
+--------------+-----------------------------------+
| Ubuntu 22.04 | ``iputils-ping 20211215-1``       |
+--------------+-----------------------------------+
| Debian 8.6   | ``iputils-ping 20121221-5+b2``    |
+--------------+-----------------------------------+
| Fedora 25    | ``iputils-20161105-1.fc25.x86_64``|
+--------------+-----------------------------------+
| Windows 10   | ``-``                             |
+--------------+-----------------------------------+
| macOS 10.13  | ``-``                             |
+--------------+-----------------------------------+

Premise
=======
``pingparsing`` expects the locale at the ping command execution environment with English.
Parsing the ``ping`` command output with any other locale may fail.
This is because the output of the ``ping`` command will change depending on the locale setting.

Documentation
===============
https://pingparsing.rtfd.io/

Sponsors
====================================
|chasbecker| |shiguredo| |b4tman| |Arturi0| |github|

.. |chasbecker| image:: https://avatars.githubusercontent.com/u/44389260?s=48&u=6da7176e51ae2654bcfd22564772ef8a3bb22318&v=4
   :target: https://github.com/chasbecker
   :alt: ex-sponsor: Charles Becker (chasbecker)
.. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48&v=4
   :target: https://github.com/shiguredo
   :alt: ex-sponsor: 時雨堂 (shiguredo)
.. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48&v=4
   :target: https://github.com/b4tman
   :alt: onetime: Dmitry Belyaev (b4tman)
.. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48&u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5&v=4
   :target: https://github.com/Arturi0
   :alt: onetime: Arturi0
.. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48&v=4
   :target: https://github.com/github
   :alt: onetime: GitHub (github)

`Become a sponsor <https://github.com/sponsors/thombashi>`__


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thombashi/pingparsing",
    "name": "pingparsing",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "cli, library, network, ping, parser, transmitter",
    "author": "Tsuyoshi Hombashi",
    "author_email": "tsuyoshi.hombashi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4d/0c/fd057b5f0a79db49c6270dedff2035a3c49685cf61a258d655a0334e01b2/pingparsing-1.4.2.tar.gz",
    "platform": null,
    "description": ".. contents:: **pingparsing**\n   :backlinks: top\n   :depth: 2\n\nSummary\n=========\n`pingparsing <https://github.com/thombashi/pingparsing>`__ is a CLI-tool/Python-library parser and transmitter for the ping command.\n\n|PyPI pkg ver| |Supported Python impl| |Supported Python ver| |CI status| |CodeQL|\n\n.. |PyPI pkg ver| image:: https://badge.fury.io/py/pingparsing.svg\n    :target: https://badge.fury.io/py/pingparsing\n    :alt: PyPI package version\n\n.. |Supported Python impl| image:: https://img.shields.io/pypi/implementation/pingparsing.svg\n    :target: https://pypi.org/project/pingparsing\n    :alt: Supported Python implementations\n\n.. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/pingparsing.svg\n    :target: https://pypi.org/project/pingparsing\n    :alt: Supported Python versions\n\n.. |CI status| image:: https://github.com/thombashi/pingparsing/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/thombashi/pingparsing/actions/workflows/ci.yml\n    :alt: CI status of Linux/macOS/Windows\n\n.. |CodeQL| image:: https://github.com/thombashi/pingparsing/actions/workflows/github-code-scanning/codeql/badge.svg\n    :target: https://github.com/thombashi/pingparsing/actions/workflows/github-code-scanning/codeql\n    :alt: CodeQL\n\nCLI Usage\n====================\nA CLI command (``pingparsing`` command) is included in the package. The command could do the following:\n\n- Execute ``ping`` and parse the result\n- Parse ping results from:\n    - file(s)\n    - the standard input\n\nExecute ping and parse the result\n--------------------------------------------\nIf you specify destination(s) to the ``pingparsing`` command as positional arguments,\nthe command executes ``ping`` for each destination(s) and parses the result.\n``ping`` will execute in parallel for multiple destinations.\nThe parsed result is outputted in JSON format.\n\n.. code-block:: console\n\n    $ pingparsing google.com\n    {\n        \"google.com\": {\n            \"destination\": \"google.com\",\n            \"packet_transmit\": 10,\n            \"packet_receive\": 10,\n            \"packet_loss_rate\": 0.0,\n            \"packet_loss_count\": 0,\n            \"rtt_min\": 34.189,\n            \"rtt_avg\": 46.054,\n            \"rtt_max\": 63.246,\n            \"rtt_mdev\": 9.122,\n            \"packet_duplicate_rate\": 0.0,\n            \"packet_duplicate_count\": 0\n        }\n    }\n\n.. code-block:: console\n\n    $ pingparsing google.com twitter.com\n    {\n        \"google.com\": {\n            \"destination\": \"google.com\",\n            \"packet_transmit\": 10,\n            \"packet_receive\": 10,\n            \"packet_loss_rate\": 0.0,\n            \"packet_loss_count\": 0,\n            \"rtt_min\": 37.341,\n            \"rtt_avg\": 44.538,\n            \"rtt_max\": 53.997,\n            \"rtt_mdev\": 5.827,\n            \"packet_duplicate_rate\": 0.0,\n            \"packet_duplicate_count\": 0\n        },\n        \"twitter.com\": {\n            \"destination\": \"twitter.com\",\n            \"packet_transmit\": 10,\n            \"packet_receive\": 10,\n            \"packet_loss_rate\": 0.0,\n            \"packet_loss_count\": 0,\n            \"rtt_min\": 45.377,\n            \"rtt_avg\": 68.819,\n            \"rtt_max\": 78.581,\n            \"rtt_mdev\": 9.769,\n            \"packet_duplicate_rate\": 0.0,\n            \"packet_duplicate_count\": 0\n        }\n    }\n\n.. code-block:: console\n\n    $ pingparsing google.com -c 3 --icmp-reply\n    {\n        \"google.com\": {\n            \"destination\": \"google.com\",\n            \"packet_transmit\": 3,\n            \"packet_receive\": 3,\n            \"packet_loss_count\": 0,\n            \"packet_loss_rate\": 0.0,\n            \"rtt_min\": 36.997,\n            \"rtt_avg\": 49.1,\n            \"rtt_max\": 60.288,\n            \"rtt_mdev\": 9.533,\n            \"packet_duplicate_count\": 0,\n            \"packet_duplicate_rate\": 0.0,\n            \"icmp_replies\": [\n                {\n                    \"destination\": \"nrt20s21-in-f14.1e100.net (172.217.175.110)\",\n                    \"bytes\": 64,\n                    \"icmp_seq\": 1,\n                    \"ttl\": 113,\n                    \"time\": 50.0,\n                    \"duplicate\": false\n                },\n                {\n                    \"destination\": \"nrt20s21-in-f14.1e100.net (172.217.175.110)\",\n                    \"bytes\": 64,\n                    \"icmp_seq\": 2,\n                    \"ttl\": 113,\n                    \"time\": 60.2,\n                    \"duplicate\": false\n                },\n                {\n                    \"destination\": \"nrt20s21-in-f14.1e100.net (172.217.175.110)\",\n                    \"bytes\": 64,\n                    \"icmp_seq\": 3,\n                    \"ttl\": 113,\n                    \"time\": 36.9,\n                    \"duplicate\": false\n                }\n            ]\n        }\n    }\n\n\nParse ping result file\n--------------------------------------------\n:Input:\n    .. code-block:: console\n\n        $ cat ping.txt\n        PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.\n\n        --- 192.168.0.1 ping statistics ---\n        1688 packets transmitted, 1553 received, +1 duplicates, 7% packet loss, time 2987ms\n        rtt min/avg/max/mdev = 0.282/0.642/11.699/0.699 ms, pipe 2, ipg/ewma 1.770/0.782 ms\n        $ cat osx.txt\n        PING google.com (172.217.6.238): 56 data bytes\n        64 bytes from 172.217.6.238: icmp_seq=0 ttl=53 time=20.482 ms\n        64 bytes from 172.217.6.238: icmp_seq=1 ttl=53 time=32.550 ms\n        64 bytes from 172.217.6.238: icmp_seq=2 ttl=53 time=32.013 ms\n        64 bytes from 172.217.6.238: icmp_seq=3 ttl=53 time=28.498 ms\n        64 bytes from 172.217.6.238: icmp_seq=4 ttl=53 time=46.093 ms\n\n        --- google.com ping statistics ---\n        5 packets transmitted, 5 packets received, 0.0% packet loss\n        round-trip min/avg/max/stddev = 20.482/31.927/46.093/8.292 ms\n\n:Output:\n    .. code-block:: console\n\n        $ pingparsing ping.txt osx.txt\n        {\n            \"osx.txt\": {\n                \"destination\": \"google.com\",\n                \"packet_transmit\": 5,\n                \"packet_receive\": 5,\n                \"packet_loss_rate\": 0.0,\n                \"packet_loss_count\": 0,\n                \"rtt_min\": 20.482,\n                \"rtt_avg\": 31.927,\n                \"rtt_max\": 46.093,\n                \"rtt_mdev\": 8.292,\n                \"packet_duplicate_rate\": null,\n                \"packet_duplicate_count\": null\n            },\n            \"ping.txt\": {\n                \"destination\": \"192.168.0.1\",\n                \"packet_transmit\": 1688,\n                \"packet_receive\": 1553,\n                \"packet_loss_rate\": 7.997630331753558,\n                \"packet_loss_count\": 135,\n                \"rtt_min\": 0.282,\n                \"rtt_avg\": 0.642,\n                \"rtt_max\": 11.699,\n                \"rtt_mdev\": 0.699,\n                \"packet_duplicate_rate\": 0.0643915003219575,\n                \"packet_duplicate_count\": 1\n            }\n        }\n\n    .. code-block:: console\n\n        $ pingparsing ping.txt osx.txt --icmp-reply\n        {\n            \"ping.txt\": {\n                \"destination\": \"google.com\",\n                \"packet_transmit\": 60,\n                \"packet_receive\": 60,\n                \"packet_loss_count\": 0,\n                \"packet_loss_rate\": 0.0,\n                \"rtt_min\": 61.425,\n                \"rtt_avg\": 99.731,\n                \"rtt_max\": 212.597,\n                \"rtt_mdev\": 27.566,\n                \"packet_duplicate_count\": 0,\n                \"packet_duplicate_rate\": 0.0,\n                \"icmp_replies\": []\n            },\n            \"osx.txt\": {\n                \"destination\": \"google.com\",\n                \"packet_transmit\": 5,\n                \"packet_receive\": 5,\n                \"packet_loss_count\": 0,\n                \"packet_loss_rate\": 0.0,\n                \"rtt_min\": 20.482,\n                \"rtt_avg\": 31.927,\n                \"rtt_max\": 46.093,\n                \"rtt_mdev\": 8.292,\n                \"packet_duplicate_count\": 0,\n                \"packet_duplicate_rate\": 0.0,\n                \"icmp_replies\": [\n                    {\n                        \"icmp_seq\": 0,\n                        \"ttl\": 53,\n                        \"time\": 20.482,\n                        \"duplicate\": false\n                    },\n                    {\n                        \"icmp_seq\": 1,\n                        \"ttl\": 53,\n                        \"time\": 32.55,\n                        \"duplicate\": false\n                    },\n                    {\n                        \"icmp_seq\": 2,\n                        \"ttl\": 53,\n                        \"time\": 32.013,\n                        \"duplicate\": false\n                    },\n                    {\n                        \"icmp_seq\": 3,\n                        \"ttl\": 53,\n                        \"time\": 28.498,\n                        \"duplicate\": false\n                    },\n                    {\n                        \"icmp_seq\": 4,\n                        \"ttl\": 53,\n                        \"time\": 46.093,\n                        \"duplicate\": false\n                    }\n                ]\n            }\n        }\n\n\nParse from the standard input\n--------------------------------------------\n.. code-block:: console\n\n    $ ping -i 0.2 -w 20 192.168.2.101 | pingparsing -\n    {\n        \"destination\": \"192.168.2.101\",\n        \"packet_transmit\": 99,\n        \"packet_receive\": 88,\n        \"packet_loss_count\": 11,\n        \"packet_loss_rate\": 11.11111111111111,\n        \"rtt_min\": 1.615,\n        \"rtt_avg\": 26.581,\n        \"rtt_max\": 93.989,\n        \"rtt_mdev\": 19.886,\n        \"packet_duplicate_count\": 0,\n        \"packet_duplicate_rate\": 0.0\n    }\n\nCLI help\n--------------------------------------------\n::\n\n    usage: pingparsing [-h] [-V] [--max-workers MAX_WORKERS]\n                       [--timestamp {none,epoch,datetime}] [-c COUNT]\n                       [-s PACKET_SIZE] [--ttl TTL] [-w DEADLINE]\n                       [--timeout TIMEOUT] [-I INTERFACE] [--addopts OPTIONS]\n                       [--indent INDENT] [--icmp-reply] [--timezone TIMEZONE]\n                       [--no-color] [--debug | --quiet]\n                       destination_or_file [destination_or_file ...]\n\n    positional arguments:\n      destination_or_file   Destinations to send ping or files to parse. '-' for\n                            parsing the standard input.\n\n    options:\n      -h, --help            show this help message and exit\n      -V, --version         show program's version number and exit\n      --max-workers MAX_WORKERS\n                            Number of threads for when multiple destinations/files\n                            are specified. Defaults to equal two times the number\n                            of cores.\n      --debug               for debug print.\n      --quiet               suppress execution log messages.\n\n    Ping Options:\n      --timestamp {none,epoch,datetime}\n                            [Only for LINUX] none: no timestamps. epoch: add\n                            timestamps with UNIX epoch time format. datetime: add\n                            timestamps with ISO time format.\n      -c COUNT, --count COUNT\n                            Stop after sending the count. see also ping(8) [-c\n                            count] option description.\n      -s PACKET_SIZE, --packet-size PACKET_SIZE\n                            Specifies the number of data bytes to be sent.\n      --ttl TTL             Specifies the Time to Live.\n      -w DEADLINE, --deadline DEADLINE\n                            Timeout before ping exits. valid time units are:\n                            d/day/days, h/hour/hours, m/min/mins/minute/minutes,\n                            s/sec/secs/second/seconds,\n                            ms/msec/msecs/millisecond/milliseconds,\n                            us/usec/usecs/microsecond/microseconds. if no unit\n                            string found, considered seconds as the time unit. see\n                            also ping(8) [-w deadline] option description. note:\n                            meaning of the 'deadline' may differ system from to\n                            system.\n      --timeout TIMEOUT     Time to wait for a response per packet. Valid time\n                            units are: d/day/days, h/hour/hours,\n                            m/min/mins/minute/minutes, s/sec/secs/second/seconds,\n                            ms/msec/msecs/millisecond/milliseconds,\n                            us/usec/usecs/microsecond/microseconds. If no unit\n                            string is found, consider milliseconds as the time\n                            unit. Attempt to send packets with milliseconds\n                            granularity in default. If the system does not support\n                            timeout in milliseconds, round up as seconds. Use\n                            system default if not specified. This option will be\n                            ignored if the system does not support timeout itself.\n                            See also ping(8) [-W timeout] option description.\n                            note: meaning of the 'timeout' may differ from system\n                            to system.\n      -I INTERFACE, --interface INTERFACE\n                            network interface\n      --addopts OPTIONS     extra command line options\n\n    Output Options:\n      --indent INDENT       JSON output will be pretty-printed with the indent\n                            level. (default= 4)\n      --icmp-reply, --icmp-replies\n                            print results for each ICMP packet reply.\n      --timezone TIMEZONE   Time zone for timestamps.\n      --no-color            Turn off colors.\n\n    Documentation: https://pingparsing.rtfd.io/\n    Issue tracker: https://github.com/thombashi/pingparsing/issues\n\nLibrary Usage\n====================\n\nExecute ping and parse the result\n--------------------------------------------\n``PingTransmitter`` class can execute ``ping`` command and obtain the\nping output as a string.\n\n:Sample Code:\n    .. code-block:: python\n\n        import json\n        import pingparsing\n\n        ping_parser = pingparsing.PingParsing()\n        transmitter = pingparsing.PingTransmitter()\n        transmitter.destination = \"google.com\"\n        transmitter.count = 10\n        result = transmitter.ping()\n\n        print(json.dumps(ping_parser.parse(result).as_dict(), indent=4))\n\n:Output:\n    .. code-block:: json\n\n        {\n            \"destination\": \"google.com\",\n            \"packet_transmit\": 10,\n            \"packet_receive\": 10,\n            \"packet_loss_rate\": 0.0,\n            \"packet_loss_count\": 0,\n            \"rtt_min\": 34.458,\n            \"rtt_avg\": 51.062,\n            \"rtt_max\": 62.943,\n            \"rtt_mdev\": 8.678,\n            \"packet_duplicate_rate\": 0.0,\n            \"packet_duplicate_count\": 0\n        }\n\n\nParsing ``ping`` command output\n-------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        import json\n        from textwrap import dedent\n        import pingparsing\n\n        parser = pingparsing.PingParsing()\n        stats = parser.parse(dedent(\"\"\"\\\n            PING google.com (74.125.24.100) 56(84) bytes of data.\n            [1524930937.003555] 64 bytes from 74.125.24.100: icmp_seq=1 ttl=39 time=148 ms\n            [1524930937.787175] 64 bytes from 74.125.24.100: icmp_seq=2 ttl=39 time=137 ms\n            [1524930938.787642] 64 bytes from 74.125.24.100: icmp_seq=3 ttl=39 time=137 ms\n            [1524930939.787653] 64 bytes from 74.125.24.100: icmp_seq=4 ttl=39 time=136 ms\n            [1524930940.788365] 64 bytes from 74.125.24.100: icmp_seq=5 ttl=39 time=136 ms\n\n            --- google.com ping statistics ---\n            5 packets transmitted, 5 received, 0% packet loss, time 4001ms\n            rtt min/avg/max/mdev = 136.537/139.174/148.006/4.425 ms\n            \"\"\"))\n\n        print(\"[extract ping statistics]\")\n        print(json.dumps(stats.as_dict(), indent=4))\n\n        print(\"\\n[extract icmp replies]\")\n        for icmp_reply in stats.icmp_replies:\n            print(icmp_reply)\n\n:Output:\n    ::\n\n        [ping statistics]\n        {\n            \"destination\": \"google.com\",\n            \"packet_transmit\": 5,\n            \"packet_receive\": 5,\n            \"packet_loss_count\": 0,\n            \"packet_loss_rate\": 0.0,\n            \"rtt_min\": 136.537,\n            \"rtt_avg\": 139.174,\n            \"rtt_max\": 148.006,\n            \"rtt_mdev\": 4.425,\n            \"packet_duplicate_count\": 0,\n            \"packet_duplicate_rate\": 0.0\n        }\n\n        [icmp replies]\n        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 37, 3555), 'icmp_seq': 1, 'ttl': 39, 'time': 148.0, 'duplicate': False}\n        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 37, 787175), 'icmp_seq': 2, 'ttl': 39, 'time': 137.0, 'duplicate': False}\n        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 38, 787642), 'icmp_seq': 3, 'ttl': 39, 'time': 137.0, 'duplicate': False}\n        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 39, 787653), 'icmp_seq': 4, 'ttl': 39, 'time': 136.0, 'duplicate': False}\n        {'destination': '74.125.24.100', 'bytes': 64, 'timestamp': datetime.datetime(2018, 4, 29, 0, 55, 40, 788365), 'icmp_seq': 5, 'ttl': 39, 'time': 136.0, 'duplicate': False}\n\n\nRecommended ping command execution\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nThe following methods are recommended to execute ``ping`` command to get the output for parsing.\nThese commands include an operation that changes the locale setting to English temporarily.\n\nLinux\n^^^^^\n.. code:: console\n\n    LC_ALL=C ping <host or IP address> -w <seconds> [option] > <output.file>\n\nWindows\n^^^^^^^\n.. code:: console\n\n    > chcp\n    Active code page: <XXX>    # get current code page\n\n    > chcp 437    # change code page to english\n    > ping <host or IP address> -n <ping count> > <output.file>\n    > chcp <XXX>    # restore code page\n\n-  Reference\n    - https://technet.microsoft.com/en-us/library/cc733037\n\nInstallation\n============\n::\n\n    pip install pingparsing\n\n\nDependencies\n============\n- Python 3.7+\n- `Python package dependencies (automatically installed) <https://github.com/thombashi/pingparsing/network/dependencies>`__\n\nOptional Dependencies\n------------------------------------\n- pingparsing[cli] extras\n    - `loguru <https://github.com/Delgan/loguru>`__\n        - Used for logging if the package installed\n    - `Pygments <http://pygments.org/>`__\n        - Syntax highlighting to ``pingparsing`` command output when installed\n\n\nDocker Image\n==================\n`thombashi/pingparsing - Docker Hub <https://hub.docker.com/r/thombashi/pingparsing/>`__\n\nSupported Environments\n============================\n- Linux\n- Windows\n- macOS\n\nTested Environments\n---------------------------\n\n+--------------+-----------------------------------+\n| OS           | ping version                      |\n+==============+===================================+\n| Ubuntu 16.04 | ``iputils-ping 20121221-5ubuntu2``|\n+--------------+-----------------------------------+\n| Ubuntu 18.04 | ``iputils-ping 20161105-1ubuntu2``|\n+--------------+-----------------------------------+\n| Ubuntu 20.04 | ``iputils-ping 20190709-3``       |\n+--------------+-----------------------------------+\n| Ubuntu 22.04 | ``iputils-ping 20211215-1``       |\n+--------------+-----------------------------------+\n| Debian 8.6   | ``iputils-ping 20121221-5+b2``    |\n+--------------+-----------------------------------+\n| Fedora 25    | ``iputils-20161105-1.fc25.x86_64``|\n+--------------+-----------------------------------+\n| Windows 10   | ``-``                             |\n+--------------+-----------------------------------+\n| macOS 10.13  | ``-``                             |\n+--------------+-----------------------------------+\n\nPremise\n=======\n``pingparsing`` expects the locale at the ping command execution environment with English.\nParsing the ``ping`` command output with any other locale may fail.\nThis is because the output of the ``ping`` command will change depending on the locale setting.\n\nDocumentation\n===============\nhttps://pingparsing.rtfd.io/\n\nSponsors\n====================================\n|chasbecker| |shiguredo| |b4tman| |Arturi0| |github|\n\n.. |chasbecker| image:: https://avatars.githubusercontent.com/u/44389260?s=48&u=6da7176e51ae2654bcfd22564772ef8a3bb22318&v=4\n   :target: https://github.com/chasbecker\n   :alt: ex-sponsor: Charles Becker (chasbecker)\n.. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48&v=4\n   :target: https://github.com/shiguredo\n   :alt: ex-sponsor: \u6642\u96e8\u5802 (shiguredo)\n.. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48&v=4\n   :target: https://github.com/b4tman\n   :alt: onetime: Dmitry Belyaev (b4tman)\n.. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48&u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5&v=4\n   :target: https://github.com/Arturi0\n   :alt: onetime: Arturi0\n.. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48&v=4\n   :target: https://github.com/github\n   :alt: onetime: GitHub (github)\n\n`Become a sponsor <https://github.com/sponsors/thombashi>`__\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "pingparsing is a CLI-tool/Python-library parser and transmitter for the ping command.",
    "version": "1.4.2",
    "project_urls": {
        "Changelog": "https://github.com/thombashi/pingparsing/blob/master/CHANGELOG.md",
        "Documentation": "https://pingparsing.rtfd.io/",
        "Homepage": "https://github.com/thombashi/pingparsing",
        "Source": "https://github.com/thombashi/pingparsing",
        "Tracker": "https://github.com/thombashi/pingparsing/issues"
    },
    "split_keywords": [
        "cli",
        " library",
        " network",
        " ping",
        " parser",
        " transmitter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a3dee1a89fc88fd2e96895223313755ce178d2415b44feaca8c0b72c457de20e",
                "md5": "fb2ab403f3a33ea43e46c94e78b6a983",
                "sha256": "502769dde197a1a08e2bbdbd6937a03d282d03f8f92148ca8750169b57e3c93e"
            },
            "downloads": -1,
            "filename": "pingparsing-1.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fb2ab403f3a33ea43e46c94e78b6a983",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 26524,
            "upload_time": "2024-05-02T09:34:53",
            "upload_time_iso_8601": "2024-05-02T09:34:53.151904Z",
            "url": "https://files.pythonhosted.org/packages/a3/de/e1a89fc88fd2e96895223313755ce178d2415b44feaca8c0b72c457de20e/pingparsing-1.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d0cfd057b5f0a79db49c6270dedff2035a3c49685cf61a258d655a0334e01b2",
                "md5": "b5b2977e38940b6bb83aa7e3beb6a79c",
                "sha256": "4c65368aa3cb66457a101368f743abf4637b3fe94c19225b5c7ff5ed817e3bc7"
            },
            "downloads": -1,
            "filename": "pingparsing-1.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b5b2977e38940b6bb83aa7e3beb6a79c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 59338,
            "upload_time": "2024-05-02T09:34:55",
            "upload_time_iso_8601": "2024-05-02T09:34:55.359462Z",
            "url": "https://files.pythonhosted.org/packages/4d/0c/fd057b5f0a79db49c6270dedff2035a3c49685cf61a258d655a0334e01b2/pingparsing-1.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-02 09:34:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thombashi",
    "github_project": "pingparsing",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pingparsing"
}
        
Elapsed time: 0.23586s