8.1. Parser classes

class pingparsing.PingParsing[source]

Parser class to parsing ping command output.

parse(ping_message: Union[str, pingparsing._pingtransmitter.PingResult]) → pingparsing._stats.PingStats[source]

Parse ping command output.

Parameters

ping_message (str or PingResult) – ping command output.

Returns

Parsed result.

Return type

PingStats

class pingparsing.PingStats(*args, **kwargs)[source]
as_dict(include_icmp_replies: bool = False) → Dict[str, Optional[Union[str, int, float, Sequence[Dict[str, Union[bool, float, int, datetime.datetime]]]]]][source]

ping statistics.

Returns

Return type

dict

Examples

>>> import pingparsing
>>> parser = pingparsing.PingParsing()
>>> parser.parse(ping_result)
>>> parser.as_dict()
{
    "destination": "google.com",
    "packet_transmit": 60,
    "packet_receive": 60,
    "packet_loss_rate": 0.0,
    "packet_loss_count": 0,
    "rtt_min": 61.425,
    "rtt_avg": 99.731,
    "rtt_max": 212.597,
    "rtt_mdev": 27.566,
    "packet_duplicate_rate": 0.0,
    "packet_duplicate_count": 0
}
as_tuple() → Tuple[source]

ping statistics.

Returns

Return type

namedtuple()

Examples

>>> import pingparsing
>>> parser = pingparsing.PingParsing()
>>> parser.parse(ping_result)
>>> parser.as_tuple()
PingResult(destination='google.com', packet_transmit=60, packet_receive=60, packet_loss_rate=0.0, packet_loss_count=0, rtt_min=61.425, rtt_avg=99.731, rtt_max=212.597, rtt_mdev=27.566, packet_duplicate_rate=0.0, packet_duplicate_count=0)
property destination

The ping destination.

Returns

Return type

str

property icmp_replies

ICMP packet reply information.

Returns

Return type

list of dict

is_empty()[source]
property packet_duplicate_count

Number of duplicated packets.

Returns

None when parsing Windows ping result.

Return type

int

property packet_duplicate_rate

Percentage of duplicated packets [%].

Returns

None if the value is not a number.

Return type

float

property packet_loss_count

Number of packet losses.

Returns

None if the value is not a number.

Return type

int

property packet_loss_rate

Percentage of packet loss [%].

Returns

None if the value is not a number.

Return type

float

property packet_receive

Number of packets received.

Returns

Return type

int

property packet_transmit

Number of packets transmitted.

Returns

Return type

int

property rtt_avg

Average round trip time of transmitted ICMP packets [msec].

Returns

Return type

float

property rtt_max

Maximum round trip time of transmitted ICMP packets [msec].

Returns

Return type

float

property rtt_mdev

Standard deviation of transmitted ICMP packets.

Returns

None when parsing Windows ping result.

Return type

float

property rtt_min

Minimum round trip time of transmitted ICMP packets [msec].

Returns

Return type

float