pingparsing is a Python library for parsing ping command output.
Project description
Home-page: https://github.com/thombashi/pingparsing
Author: Tsuyoshi Hombashi
Author-email: tsuyoshi.hombashi@gmail.com
License: MIT License
Description-Content-Type: UNKNOWN
Description:
pingparsing
=============
.. image:: https://badge.fury.io/py/pingparsing.svg
:target: https://badge.fury.io/py/pingparsing
.. image:: https://img.shields.io/travis/thombashi/pingparsing/master.svg?label=Linux
:target: https://travis-ci.org/thombashi/pingparsing
.. image:: https://img.shields.io/appveyor/ci/thombashi/pingparsing/master.svg?label=Windows
:target: https://ci.appveyor.com/project/thombashi/pingparsing
.. image:: https://img.shields.io/github/stars/thombashi/pingparsing.svg?style=social&label=Star
:target: https://github.com/thombashi/pingparsing
Summary
---------
pingparsing is a Python library for parsing ping command output.
Usage
=====
Execute ping and parse the result
--------------------------------------------
``PingTransmitter`` class can execute ``ping`` command and obtain the
ping output as a string.
Sample code
~~~~~~~~~~~
https://github.com/thombashi/pingparsing/blob/master/examples/ping_sample.py
Example: Linux environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: console
./ping_sample.py google.com
# returncode ---
0
# properties ---
packet_transmit: 10 packets
packet_receive: 10 packets
packet_loss_rate: 0.0 %
packet_loss_count: 0 packets
packet_duplicate_rate: NaN
packet_duplicate_count: NaN
rtt_min: 39.087
rtt_avg: 48.312
rtt_max: 76.458
rtt_mdev: 10.551
# as_dict ---
{
"destination": "google.com",
"packet_transmit": 10,
"packet_receive": 10,
"packet_loss_rate": 0.0,
"packet_loss_count": 0,
"rtt_min": 39.087,
"rtt_avg": 48.312,
"rtt_max": 76.458,
"rtt_mdev": 10.551,
"packet_duplicate_rate": 0.0,
"packet_duplicate_count": 0
}
Example: Windows environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: console
>ping_sample.py -d google.com
# returncode ---
0
# properties ---
packet_transmit: 10 packets
packet_receive: 10 packets
packet_loss_rate: 0.0 %
packet_loss_count: 0 packets
packet_duplicate_rate: NaN
packet_duplicate_count: NaN
rtt_min: 41.0
rtt_avg: 49.0
rtt_max: 58.0
rtt_mdev: None
# as_dict ---
{
"packet_transmit": 10,
"rtt_max": 58.0,
"packet_duplicate_count": null,
"rtt_avg": 49.0,
"destination": "172.217.27.174",
"packet_receive": 10,
"packet_duplicate_rate": null,
"packet_loss_count": 0,
"rtt_min": 41.0,
"packet_loss_rate": 0.0,
"rtt_mdev": null
}
Note: ``rtt_mdev`` not available with Windows environment
Parsing ``ping`` command output
-------------------------------
Sample code
~~~~~~~~~~~
https://github.com/thombashi/pingparsing/blob/master/examples/parse_sample.py
Example: Linux environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Input:
::
# LC_ALL=C ping google.com -q -c 60 > ping.txt
# cat ping.txt
PING google.com (216.58.196.238) 56(84) bytes of data.
--- google.com ping statistics ---
60 packets transmitted, 60 received, 0% packet loss, time 59153ms
rtt min/avg/max/mdev = 61.425/99.731/212.597/27.566 ms
:Output:
.. code:: console
./parse_sample.py -f ping.txt
# properties ---
packet_transmit: 60 packets
packet_receive: 60 packets
packet_loss_rate: 0.0 %
packet_loss_count: 0 packets
packet_duplicate_rate: NaN
packet_duplicate_count: NaN
rtt_min: 61.425
rtt_avg: 99.731
rtt_max: 212.597
rtt_mdev: 27.566
# asdict ---
{
"rtt_min": 61.425,
"packet_duplicate_count": null,
"packet_loss_count": 0,
"rtt_max": 212.597,
"packet_loss_rate": 0.0,
"packet_receive": 60,
"rtt_mdev": 27.566,
"packet_transmit": 60,
"packet_duplicate_rate": null,
"rtt_avg": 99.731
}
Example: Windows environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Input:
.. code:: console
>ping google.com -n 10 > ping_win.txt
>type ping_win.txt
Pinging google.com [216.58.196.238] with 32 bytes of data:
Reply from 216.58.196.238: bytes=32 time=87ms TTL=51
Reply from 216.58.196.238: bytes=32 time=97ms TTL=51
Reply from 216.58.196.238: bytes=32 time=56ms TTL=51
Reply from 216.58.196.238: bytes=32 time=95ms TTL=51
Reply from 216.58.196.238: bytes=32 time=194ms TTL=51
Reply from 216.58.196.238: bytes=32 time=98ms TTL=51
Reply from 216.58.196.238: bytes=32 time=93ms TTL=51
Reply from 216.58.196.238: bytes=32 time=96ms TTL=51
Reply from 216.58.196.238: bytes=32 time=96ms TTL=51
Reply from 216.58.196.238: bytes=32 time=165ms TTL=51
Ping statistics for 216.58.196.238:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 56ms, Maximum = 194ms, Average = 107ms
:Output:
.. code:: console
parse_sample.py -f ping_win.txt
# properties ---
packet_transmit: 10
packet_receive: 10
packet_loss: 0.0
rtt_min: 56.0
rtt_avg: 107.0
rtt_max: 194.0
rtt_mdev: None
# asdict ---
{
"packet_loss": 0.0,
"packet_transmit": 10,
"rtt_min": 56.0,
"rtt_avg": 107.0,
"packet_receive": 10,
"rtt_max": 194.0,
"rtt_mdev": null
}
Recommended ping command execution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following methods are recommended to execute ``ping`` command for parsing.
These commands include an operation that the locale setting change 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 2.7+ or 3.3+
- `logbook <http://logbook.readthedocs.io/en/stable/>`__
- `pyparsing <https://pyparsing.wikispaces.com/>`__
- `six <https://pypi.python.org/pypi/six/>`__
- `typepy <https://github.com/thombashi/typepy>`__
Test dependencies
-----------------
- `pytest <https://pypi.python.org/pypi/pytest>`__
- `pytest-runner <https://pypi.python.org/pypi/pytest-runner>`__
- `tox <https://pypi.python.org/pypi/tox>`__
Tested Environment
==================
+--------------+-----------------------------------+
| OS | ping version |
+==============+===================================+
| Debian 8.6 | ``iputils-ping 20121221-5+b2`` |
+--------------+-----------------------------------+
| Fedora 25 | ``iputils-20161105-1.fc25.x86_64``|
+--------------+-----------------------------------+
| Windows 10 | ``-`` |
+--------------+-----------------------------------+
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
===============
http://pingparsing.rtfd.io/
Keywords: network,ping,parser,transmitter
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Networking
Author: Tsuyoshi Hombashi
Author-email: tsuyoshi.hombashi@gmail.com
License: MIT License
Description-Content-Type: UNKNOWN
Description:
pingparsing
=============
.. image:: https://badge.fury.io/py/pingparsing.svg
:target: https://badge.fury.io/py/pingparsing
.. image:: https://img.shields.io/travis/thombashi/pingparsing/master.svg?label=Linux
:target: https://travis-ci.org/thombashi/pingparsing
.. image:: https://img.shields.io/appveyor/ci/thombashi/pingparsing/master.svg?label=Windows
:target: https://ci.appveyor.com/project/thombashi/pingparsing
.. image:: https://img.shields.io/github/stars/thombashi/pingparsing.svg?style=social&label=Star
:target: https://github.com/thombashi/pingparsing
Summary
---------
pingparsing is a Python library for parsing ping command output.
Usage
=====
Execute ping and parse the result
--------------------------------------------
``PingTransmitter`` class can execute ``ping`` command and obtain the
ping output as a string.
Sample code
~~~~~~~~~~~
https://github.com/thombashi/pingparsing/blob/master/examples/ping_sample.py
Example: Linux environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: console
./ping_sample.py google.com
# returncode ---
0
# properties ---
packet_transmit: 10 packets
packet_receive: 10 packets
packet_loss_rate: 0.0 %
packet_loss_count: 0 packets
packet_duplicate_rate: NaN
packet_duplicate_count: NaN
rtt_min: 39.087
rtt_avg: 48.312
rtt_max: 76.458
rtt_mdev: 10.551
# as_dict ---
{
"destination": "google.com",
"packet_transmit": 10,
"packet_receive": 10,
"packet_loss_rate": 0.0,
"packet_loss_count": 0,
"rtt_min": 39.087,
"rtt_avg": 48.312,
"rtt_max": 76.458,
"rtt_mdev": 10.551,
"packet_duplicate_rate": 0.0,
"packet_duplicate_count": 0
}
Example: Windows environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: console
>ping_sample.py -d google.com
# returncode ---
0
# properties ---
packet_transmit: 10 packets
packet_receive: 10 packets
packet_loss_rate: 0.0 %
packet_loss_count: 0 packets
packet_duplicate_rate: NaN
packet_duplicate_count: NaN
rtt_min: 41.0
rtt_avg: 49.0
rtt_max: 58.0
rtt_mdev: None
# as_dict ---
{
"packet_transmit": 10,
"rtt_max": 58.0,
"packet_duplicate_count": null,
"rtt_avg": 49.0,
"destination": "172.217.27.174",
"packet_receive": 10,
"packet_duplicate_rate": null,
"packet_loss_count": 0,
"rtt_min": 41.0,
"packet_loss_rate": 0.0,
"rtt_mdev": null
}
Note: ``rtt_mdev`` not available with Windows environment
Parsing ``ping`` command output
-------------------------------
Sample code
~~~~~~~~~~~
https://github.com/thombashi/pingparsing/blob/master/examples/parse_sample.py
Example: Linux environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Input:
::
# LC_ALL=C ping google.com -q -c 60 > ping.txt
# cat ping.txt
PING google.com (216.58.196.238) 56(84) bytes of data.
--- google.com ping statistics ---
60 packets transmitted, 60 received, 0% packet loss, time 59153ms
rtt min/avg/max/mdev = 61.425/99.731/212.597/27.566 ms
:Output:
.. code:: console
./parse_sample.py -f ping.txt
# properties ---
packet_transmit: 60 packets
packet_receive: 60 packets
packet_loss_rate: 0.0 %
packet_loss_count: 0 packets
packet_duplicate_rate: NaN
packet_duplicate_count: NaN
rtt_min: 61.425
rtt_avg: 99.731
rtt_max: 212.597
rtt_mdev: 27.566
# asdict ---
{
"rtt_min": 61.425,
"packet_duplicate_count": null,
"packet_loss_count": 0,
"rtt_max": 212.597,
"packet_loss_rate": 0.0,
"packet_receive": 60,
"rtt_mdev": 27.566,
"packet_transmit": 60,
"packet_duplicate_rate": null,
"rtt_avg": 99.731
}
Example: Windows environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Input:
.. code:: console
>ping google.com -n 10 > ping_win.txt
>type ping_win.txt
Pinging google.com [216.58.196.238] with 32 bytes of data:
Reply from 216.58.196.238: bytes=32 time=87ms TTL=51
Reply from 216.58.196.238: bytes=32 time=97ms TTL=51
Reply from 216.58.196.238: bytes=32 time=56ms TTL=51
Reply from 216.58.196.238: bytes=32 time=95ms TTL=51
Reply from 216.58.196.238: bytes=32 time=194ms TTL=51
Reply from 216.58.196.238: bytes=32 time=98ms TTL=51
Reply from 216.58.196.238: bytes=32 time=93ms TTL=51
Reply from 216.58.196.238: bytes=32 time=96ms TTL=51
Reply from 216.58.196.238: bytes=32 time=96ms TTL=51
Reply from 216.58.196.238: bytes=32 time=165ms TTL=51
Ping statistics for 216.58.196.238:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 56ms, Maximum = 194ms, Average = 107ms
:Output:
.. code:: console
parse_sample.py -f ping_win.txt
# properties ---
packet_transmit: 10
packet_receive: 10
packet_loss: 0.0
rtt_min: 56.0
rtt_avg: 107.0
rtt_max: 194.0
rtt_mdev: None
# asdict ---
{
"packet_loss": 0.0,
"packet_transmit": 10,
"rtt_min": 56.0,
"rtt_avg": 107.0,
"packet_receive": 10,
"rtt_max": 194.0,
"rtt_mdev": null
}
Recommended ping command execution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following methods are recommended to execute ``ping`` command for parsing.
These commands include an operation that the locale setting change 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 2.7+ or 3.3+
- `logbook <http://logbook.readthedocs.io/en/stable/>`__
- `pyparsing <https://pyparsing.wikispaces.com/>`__
- `six <https://pypi.python.org/pypi/six/>`__
- `typepy <https://github.com/thombashi/typepy>`__
Test dependencies
-----------------
- `pytest <https://pypi.python.org/pypi/pytest>`__
- `pytest-runner <https://pypi.python.org/pypi/pytest-runner>`__
- `tox <https://pypi.python.org/pypi/tox>`__
Tested Environment
==================
+--------------+-----------------------------------+
| OS | ping version |
+==============+===================================+
| Debian 8.6 | ``iputils-ping 20121221-5+b2`` |
+--------------+-----------------------------------+
| Fedora 25 | ``iputils-20161105-1.fc25.x86_64``|
+--------------+-----------------------------------+
| Windows 10 | ``-`` |
+--------------+-----------------------------------+
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
===============
http://pingparsing.rtfd.io/
Keywords: network,ping,parser,transmitter
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Networking
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pingparsing-0.11.0.tar.gz
(16.0 kB
view hashes)
Built Distribution
Close
Hashes for pingparsing-0.11.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6065c995786104c1dc7c86daf5503c74977e30947aa69b43bd7a166fa51a90db |
|
MD5 | 5225db855e197d49b1e08974d5a04dc4 |
|
BLAKE2b-256 | 1c7cdaaac79633d2650c1fc33c415509c6916745cea19e2e0f8de44054f12802 |