fix(ping): parse each reply into results

The probe pattern expected "from" after icmp_seq, but iputils prints
"bytes from <ip>: icmp_seq=... time=... ms", so results was always
empty. Replies by name ("from host (ip)") and over IPv6 are read too.

Closes #12
This commit is contained in:
Christian Manivong committed 2026-11-01 21:57:36 +01:00
1 parent 29ed59c8d1
commit 10cf788b86
3 files changed
+34 -3

No files matched your search

+7 -3
View File
@@ -23,6 +23,10 @@ import napalm.base.constants as C
_JsonDict = dict[str, Any]
#: One reply in iputils' ping output, by address or by name with the address
#: in brackets: "64 bytes from dns.google (8.8.4.4): icmp_seq=1 ttl=118 time=10.5 ms".
_PING_REPLY = re.compile(r"bytes from (?:\S+ \()?([0-9a-fA-F.:]+)\)?: .*?time=([\d.]+) ms")
class ProxmoxRoutingMixin:
"""Mixin providing routing NAPALM methods (get_route_to, ping, traceroute)."""
@@ -90,9 +94,9 @@ class ProxmoxRoutingMixin:
rtt_std = float(m_rtt.group(4)) if m_rtt else 0.0
# Individual probe lines
probes = []
for m_probe in re.finditer(r"icmp_seq=\d+.*?time=([\d.]+) ms.*?from ([\d.a-fA-F:]+)", raw):
probes.append({"ip_address": m_probe.group(2), "rtt": float(m_probe.group(1))})
probes = [
{"ip_address": m.group(1), "rtt": float(m.group(2))} for m in _PING_REPLY.finditer(raw)
]
return {
"success": {