Giter Club home page Giter Club logo

pingparser's Introduction

pingparser

pingparser parses the output of the system ping or ping6 command.

Yay, Travis status:

https://travis-ci.org/ssteinerx/pingparser.svg?branch=master

Usage

You can pipe ping command output into pingparser.py on the command line, which outputs the parsed result to stdout in a customizable output format (see ./pingparser.py --help for details):

$ ping -c 5 www.google.com | ./pingparser.py -f '%h %s %r %p %m %M %a'
www.l.google.com 5 5 0 14.711 26.378 19.621

Or in Python you can call pingparser.parse(ping_output), which returns a dictionary containing the parsed fields:

>>> import pingparser
>>> from collections import OrderedDict
>>> results = pingparser.parse('''
... PING www.l.google.com (74.125.225.84) 56(84) bytes of data.
... 64 bytes from 74.125.225.84: icmp_req=1 ttl=55 time=13.9 ms
... 64 bytes from 74.125.225.84: icmp_req=2 ttl=55 time=21.4 ms
...
... --- www.l.google.com ping statistics ---
... 2 packets transmitted, 2 received, 0% packet loss, time 5072ms
... rtt min/avg/max/mdev = 13.946/17.682/21.418/3.736 ms''')
>>> OrderedDict(sorted(results.items()))
OrderedDict([('avgping', '17.682'), ('host', 'www.l.google.com'), ('jitter', '3.736'), ('maxping', '21.418'), ('minping', '13.946'), ('packet_loss', '0'), ('received', '2'), ('sent', '2')])

Installing

Download the source and run:

$ python setup.py install

Tests

To run the tests, first install tox:

$ pip install tox

then run tox from the project root directory:

$ tox

pingparser's People

Contributors

emmdim avatar gg avatar karimerto avatar ssteinerx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pingparser's Issues

Error/filtered packet not handle by pingparser

Having an error (in this case a filtered packet) causes pingparser to raise an exception. This may be a known issue or a feature. See code below

Traceback (most recent call last):
  File "./checkSat.py", line 32, in <module>
    ping_results = pingparser.parse(cmd_output)
  File "/usr/local/lib/python2.7/dist-packages/pingparser-0.4-py2.7.egg/pingparser.py", line 77, in parse
    sent, received, packet_loss = _get_match_groups(ping_output, rslt_matcher)
  File "/usr/local/lib/python2.7/dist-packages/pingparser-0.4-py2.7.egg/pingparser.py", line 55, in _get_match_groups
    raise Exception('Invalid PING output:\n' + ping_output)
Exception: Invalid PING output:
PING 10.1.60.1 (10.1.60.1) 56(84) bytes of data.
From x.x.x.x icmp_seq=7 Packet filtered

--- 10.1.60.1 ping statistics ---
7 packets transmitted, 0 received, +1 errors, 100% packet loss, time 6035ms

timestamp addition

Hi, thanks @ssteinerx for your effort !!! I would like to ask if it possible to parse a ping -D command? to get the time since epoch at least and then if we output to a file we could have a timestamp? Thanks

Publish to PyPi

Could you please publish pingparser to pypi.python.org? It would greatly simplify distribution of packages that depend on pingparser.

ipv6 ping failed to parse

Executing next command on side: ping -6 fec0::2 -c 2
Stdout from host PING fec0::2(fec0::2) 56 data bytes
64 bytes from fec0::2: icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from fec0::2: icmp_seq=2 ttl=64 time=0.034 ms

File "throughput.py", line 464, in ping_execute
parsed_ping_result = pingparser.parse(result)
File "build/bdist.linux-x86_64/egg/pingparser.py", line 76, in parse
File "build/bdist.linux-x86_64/egg/pingparser.py", line 55, in _get_match_groups
Exception: Invalid PING output:
PING fec0::2(fec0::2) 56 data bytes
64 bytes from fec0::2: icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from fec0::2: icmp_seq=2 ttl=64 time=0.034 ms

--- fec0::2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.025/0.029/0.034/0.007 ms

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.