(target, count=4)
| 87 | return default |
| 88 | return max(lo, min(hi, n)) |
| 89 | |
| 90 | |
| 91 | def _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 | |
| 109 | def _have(binname): |
| 110 | return shutil.which(binname) is not None |
| 111 | |
| 112 | |
| 113 | def _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 |
no test coverage detected