Skip to content

Commit bc7a9fc

Browse files
committed
Add Cisco-style output format
1 parent afa1e95 commit bc7a9fc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pythonping/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def ping(target,
2121
out=sys.stdout,
2222
match=False,
2323
source=None,
24-
out_format='legacy'):
24+
out_format='legacy',
25+
cisco=False):
2526
"""Pings a remote host and handles the responses
2627
2728
:param target: The remote hostname or IP address to ping
@@ -85,4 +86,16 @@ def ping(target,
8586

8687
SEED_IDs.remove(seed_id)
8788

89+
if cisco:
90+
# Cisco-like summary
91+
sent = comm.responses.stats_packets_sent
92+
received = comm.responses.stats_packets_returned
93+
loss = int((1 - received / sent) * 100)
94+
min_rtt = comm.responses.rtt_min_ms
95+
avg_rtt = comm.responses.rtt_avg_ms
96+
max_rtt = comm.responses.rtt_max_ms
97+
98+
print(f"\nSuccess rate is {received}/{sent} ({100 - loss}%), "
99+
f"round-trip min/avg/max = {min_rtt}/{avg_rtt}/{max_rtt} ms", file=out)
100+
88101
return comm.responses

0 commit comments

Comments
 (0)