From bc7a9fc2c76b3571e321a6e6866393f20e3f2ca1 Mon Sep 17 00:00:00 2001 From: MangoLulu221 Date: Wed, 2 Jul 2025 23:09:34 +0800 Subject: [PATCH] Add Cisco-style output format --- pythonping/__init__.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pythonping/__init__.py b/pythonping/__init__.py index 2b3c29e..93bcf39 100644 --- a/pythonping/__init__.py +++ b/pythonping/__init__.py @@ -21,7 +21,8 @@ def ping(target, out=sys.stdout, match=False, source=None, - out_format='legacy'): + out_format='legacy', + cisco=False): """Pings a remote host and handles the responses :param target: The remote hostname or IP address to ping @@ -85,4 +86,16 @@ def ping(target, SEED_IDs.remove(seed_id) + if cisco: + # Cisco-like summary + sent = comm.responses.stats_packets_sent + received = comm.responses.stats_packets_returned + loss = int((1 - received / sent) * 100) + min_rtt = comm.responses.rtt_min_ms + avg_rtt = comm.responses.rtt_avg_ms + max_rtt = comm.responses.rtt_max_ms + + print(f"\nSuccess rate is {received}/{sent} ({100 - loss}%), " + f"round-trip min/avg/max = {min_rtt}/{avg_rtt}/{max_rtt} ms", file=out) + return comm.responses