7.1. 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

7.1.1. 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.

Execute with a single destination
$ 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
    }
}
Execute with multiple destinations
$ 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
    }
}
Print ICMP packet replies
$ 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
            }
        ]
    }
}

7.1.2. Parse ping result file

Input
$ 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
Parse multiple ping result files
$ 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
    }
}
Print ICMP packet replies
$ 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
            }
        ]
    }
}

7.1.3. Parse from the standard input

$ 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
}

7.1.4. 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