MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / do_ping

Function do_ping

network_diagnostics.py:89–112  ·  view source on GitHub ↗
(target, count=4)

Source from the content-addressed store, hash-verified

87 return default
88 return max(lo, min(hi, n))
89
90
91def _run(cmd, timeout=30, env=None):
92 """Run a command (list of args) and return {rc, out, err}.
93
94 Never raises: missing binary -> rc 127, timeout -> rc 124.
95 """
96 try:
97 r = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout,
98 env=env)
99 return {'rc': r.returncode, 'out': r.stdout, 'err': r.stderr}
100 except FileNotFoundError:
101 return {'rc': 127, 'out': '',
102 'err': f"{cmd[0]}: not installed (run the Ragnar installer/update to add it)"}
103 except subprocess.TimeoutExpired:
104 return {'rc': 124, 'out': '', 'err': f"{cmd[0]}: timed out after {timeout}s"}
105 except Exception as e: # pragma: no cover - defensive
106 return {'rc': 1, 'out': '', 'err': str(e)}
107
108
109def _have(binname):
110 return shutil.which(binname) is not None
111
112
113def _have_scapy():
114 """True if the Scapy Python module is importable (not just the CLI). Scapy is
115 optional — only the scanners' end-to-end self-test leg uses it — so this is a

Callers 1

net_pingFunction · 0.85

Calls 2

_clamp_intFunction · 0.85
_runFunction · 0.85

Tested by

no test coverage detected