8.1. Parser classes

class pingparsing.PingParsing(timezone: tzinfo | None = None)[source]

Parser class to parsing ping command output.

Parameters:

timezone (Optional[tzinfo]) – Time zone for parsing timestamps.

parse(ping_message: str | PingResult) 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, str | int | float | Sequence[Dict[str, str | bool | float | int | datetime]] | None][source]

ping statistics.

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.

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: str

The ping destination.

Return type:

str

property icmp_replies: Sequence[Dict[str, str | bool | float | int | datetime]]

ICMP packet reply information.

Return type:

list of dict

is_empty()[source]
property packet_duplicate_count: int | None

Number of duplicated packets.

Returns:

None when parsing Windows ping result.

Return type:

int

property packet_duplicate_rate: float | None

Percentage of duplicated packets [%].

Returns:

None if the value is not a number.

Return type:

float

property packet_loss_count: int | None

Number of packet losses.

Returns:

None if the value is not a number.

Return type:

int

property packet_loss_rate: float | None

Percentage of packet loss [%].

Returns:

None if the value is not a number.

Return type:

float

property packet_receive: int | None

Number of packets received.

Return type:

int

property packet_transmit: int | None

Number of packets transmitted.

Return type:

int

property rtt_avg: float | None

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

Return type:

float

property rtt_max: float | None

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

Return type:

float

property rtt_mdev: float | None

Standard deviation of transmitted ICMP packets.

Returns:

None when parsing Windows ping result.

Return type:

float

property rtt_min: float | None

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

Return type:

float