whatsrunning 0.0.0-stage → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # whatsrunning
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ See what every device on **your own** home network is talking to — from your
4
+ laptop, with no router changes and no extra hardware.
5
+
6
+ ```bash
7
+ npx whatsrunning detect # show the network you're on
8
+ sudo npx whatsrunning discover # list the devices on it
9
+ sudo npx whatsrunning spoof # monitor it live in your terminal
10
+ ```
11
+
12
+ Or install it so `whatsrunning` is always on your PATH:
13
+
14
+ ```bash
15
+ npm install -g whatsrunning
16
+ ```
17
+
18
+ > **0.6 known issues:** stop `spoof` with **Ctrl-C** and wait for "Network
19
+ > restored" — don't close the terminal while it runs, or the network restore
20
+ > can be skipped. On Linux with Docker/ufw, forwarded traffic may be dropped.
21
+ > Details: [Known issues](https://github.com/dmoney25632/whatsrunning#known-issues-in-06-read-before-running-spoof).
22
+
23
+ ## Requires Python 3.9+
24
+
25
+ whatsrunning's engine is Python — packet capture needs raw sockets and
26
+ `libpcap`, which Node can't do cleanly. **This npm package is a launcher.** On
27
+ the first run it finds Python 3, creates a private virtual environment
28
+ (`~/.cache/whatsrunning` on macOS/Linux, `%LOCALAPPDATA%\whatsrunning\venv` on
29
+ Windows), installs the bundled engine into it (needs internet once), and from
30
+ then on just runs it. You need:
31
+
32
+ - **Python 3.9+** on your PATH (`brew install python`;
33
+ `sudo apt install python3 python3-venv`; or python.org on Windows with
34
+ "Add to PATH")
35
+ - **macOS, Linux or Windows 11**. On **Windows**, packet capture also needs
36
+ [Npcap](https://npcap.com) — install it with the default options (you do
37
+ **not** need "WinPcap API-compatible mode" or "Support raw 802.11 traffic").
38
+
39
+ Capture needs elevation, the same as Wireshark/tcpdump: `sudo` on macOS/Linux,
40
+ or an **Administrator** terminal on Windows. On macOS/Linux the first `sudo`
41
+ run does its own one-time setup; on Windows the setup lives under your user's
42
+ `%LOCALAPPDATA%`.
43
+
44
+ ## What it does
45
+
46
+ - Inventories every device on the network (IP, MAC, maker, name)
47
+ - With your explicit confirmation, observes per-device traffic **metadata**:
48
+ DNS lookups, the site name in HTTPS connections (TLS SNI), bytes up/down, and
49
+ timing — then labels each connection (ads, tracking, telemetry, video, ...)
50
+ - A live terminal view and a local web dashboard (`whatsrunning ui`)
51
+
52
+ It reports **names and volumes, not contents** — HTTPS stays encrypted. Use it
53
+ only on a network you own and administer.
54
+
55
+ Full docs and source: https://github.com/dmoney25632/whatsrunning
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /*
5
+ * npm launcher for whatsrunning.
6
+ *
7
+ * whatsrunning's engine is Python (packet capture needs raw sockets + libpcap,
8
+ * which Node can't do cleanly). This launcher makes `npx whatsrunning` work
9
+ * anyway: it finds Python 3, sets up a private virtual environment on first
10
+ * run, installs the bundled engine wheel into it, then runs the real CLI and
11
+ * passes your arguments straight through.
12
+ *
13
+ * Works on macOS, Linux and Windows 11. Requires Python 3.9+ on PATH. On
14
+ * Windows, packet capture additionally needs Npcap (https://npcap.com).
15
+ */
16
+
17
+ const { spawn, spawnSync } = require("child_process");
18
+ const fs = require("fs");
19
+ const os = require("os");
20
+ const path = require("path");
21
+
22
+ const isWin = process.platform === "win32";
23
+ // Commands that capture packets — they need admin/root, and Npcap on Windows.
24
+ const CAPTURE_CMDS = new Set(["spoof", "discover"]);
25
+
26
+ function log(msg) {
27
+ process.stderr.write(`[whatsrunning] ${msg}\n`);
28
+ }
29
+
30
+ // Candidate Python launchers, each as an argv prefix. On Windows the `py`
31
+ // launcher and the real python come before the Microsoft Store `python.exe`
32
+ // alias stub (which just opens the Store); we detect a working one by actually
33
+ // running it and checking the version prints.
34
+ function pythonCandidates() {
35
+ if (isWin) return [["py", "-3"], ["python"], ["python3"]];
36
+ return [["python3"], ["python"]];
37
+ }
38
+
39
+ function findPython() {
40
+ for (const prefix of pythonCandidates()) {
41
+ const r = spawnSync(prefix[0], [...prefix.slice(1),
42
+ "-c", "import sys;print('%d.%d' % sys.version_info[:2])"],
43
+ { encoding: "utf8" });
44
+ if (r.status === 0 && r.stdout) {
45
+ const [maj, min] = r.stdout.trim().split(".").map(Number);
46
+ if (maj === 3 && min >= 9) return prefix;
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+
52
+ function venvDir() {
53
+ if (isWin) {
54
+ const base = process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local");
55
+ return path.join(base, "whatsrunning", "venv");
56
+ }
57
+ const cacheRoot = process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
58
+ return path.join(cacheRoot, "whatsrunning", "venv");
59
+ }
60
+
61
+ function venvPython(dir) {
62
+ return isWin
63
+ ? path.join(dir, "Scripts", "python.exe")
64
+ : path.join(dir, "bin", "python");
65
+ }
66
+
67
+ function bundledWheel() {
68
+ const vendor = path.join(__dirname, "..", "vendor");
69
+ let whls = [];
70
+ try {
71
+ whls = fs.readdirSync(vendor).filter((f) => f.endsWith(".whl"));
72
+ } catch (e) {
73
+ return null;
74
+ }
75
+ if (!whls.length) return null;
76
+ whls.sort();
77
+ return path.join(vendor, whls[whls.length - 1]);
78
+ }
79
+
80
+ function ensureEngine(pyPrefix) {
81
+ const dir = venvDir();
82
+ const vpy = venvPython(dir);
83
+ const wheel = bundledWheel();
84
+ if (!wheel) {
85
+ log("internal error: bundled engine wheel is missing.");
86
+ process.exit(1);
87
+ }
88
+ const marker = path.join(dir, ".installed");
89
+ const want = path.basename(wheel);
90
+ const upToDate = fs.existsSync(vpy) && fs.existsSync(marker) &&
91
+ fs.readFileSync(marker, "utf8").trim() === want;
92
+
93
+ if (!upToDate) {
94
+ log("first run: setting up the Python engine (one time, needs internet)...");
95
+ fs.mkdirSync(path.dirname(dir), { recursive: true });
96
+ let r = spawnSync(pyPrefix[0], [...pyPrefix.slice(1), "-m", "venv", dir],
97
+ { stdio: "inherit" });
98
+ if (r.status !== 0) {
99
+ log("could not create a Python virtual environment.");
100
+ log("make sure the venv module is available (Debian/Ubuntu: sudo apt install python3-venv).");
101
+ process.exit(1);
102
+ }
103
+ // Upgrade pip FIRST: the pip bundled with Python 3.9 is too old to install
104
+ // some wheels/metadata cleanly. Only then install the engine wheel.
105
+ spawnSync(vpy, ["-m", "pip", "install", "--quiet", "--upgrade", "pip"], { stdio: "inherit" });
106
+ r = spawnSync(vpy, ["-m", "pip", "install", "--quiet", wheel], { stdio: "inherit" });
107
+ if (r.status !== 0) {
108
+ log("could not install the engine.");
109
+ process.exit(1);
110
+ }
111
+ fs.writeFileSync(marker, want);
112
+ log("setup complete.");
113
+ }
114
+ return vpy;
115
+ }
116
+
117
+ function npcapInstalled() {
118
+ const root = process.env.SystemRoot || "C:\\Windows";
119
+ return fs.existsSync(path.join(root, "System32", "Npcap", "wpcap.dll")) ||
120
+ fs.existsSync(path.join(root, "System32", "wpcap.dll"));
121
+ }
122
+
123
+ function isElevated() {
124
+ if (isWin) {
125
+ // `net session` succeeds only from an elevated prompt.
126
+ const r = spawnSync("net", ["session"], { stdio: "ignore" });
127
+ return r.status === 0;
128
+ }
129
+ return typeof process.getuid === "function" && process.getuid() === 0;
130
+ }
131
+
132
+ function adminHint() {
133
+ if (isWin) {
134
+ return "This needs Administrator rights. Open Terminal as Administrator, then run: npx whatsrunning spoof";
135
+ }
136
+ return "This needs root. Re-run with: sudo npx whatsrunning spoof";
137
+ }
138
+
139
+ function main() {
140
+ const py = findPython();
141
+ if (!py) {
142
+ log("needs Python 3.9+ on your PATH.");
143
+ log(" macOS: brew install python");
144
+ log(" Debian/Ubuntu: sudo apt install python3 python3-venv");
145
+ log(" Windows: install Python 3 from https://python.org (tick 'Add to PATH')");
146
+ process.exit(1);
147
+ }
148
+
149
+ const args = process.argv.slice(2);
150
+ const cmd = args.find((a) => !a.startsWith("-"));
151
+
152
+ if (CAPTURE_CMDS.has(cmd)) {
153
+ if (isWin && !npcapInstalled()) {
154
+ log("packet capture on Windows needs Npcap.");
155
+ log("install it from https://npcap.com (default options are fine; you do NOT");
156
+ log("need 'WinPcap API-compatible mode' or 'Support raw 802.11 traffic').");
157
+ process.exit(1);
158
+ }
159
+ if (!isElevated()) {
160
+ log(adminHint());
161
+ process.exit(1);
162
+ }
163
+ }
164
+
165
+ const vpy = ensureEngine(py);
166
+ runEngine(vpy, args, bundledWheel());
167
+ }
168
+
169
+ // Which signals to pass on to the engine. The engine restores the network when
170
+ // it is interrupted, so it must (a) get the signal when only this launcher is
171
+ // signalled (`kill <pid>`, a supervisor, a closed pipe), (b) NOT get it twice
172
+ // when the terminal already delivered it to the whole foreground process group
173
+ // (Ctrl-C, terminal hang-up) — a second signal mid-restore is exactly what the
174
+ // engine guards against — and (c) be waited for, so the shell prompt only
175
+ // returns once the restore has finished.
176
+ function forwardedSignals(platform, interactive) {
177
+ if (platform === "win32") {
178
+ // Ctrl-C / Ctrl-Break / console close reach every process attached to the
179
+ // console, the engine included. Never re-send them; just stay alive.
180
+ return [];
181
+ }
182
+ // SIGTERM is never sent by the terminal: always forward it. SIGINT/SIGHUP
183
+ // come from the terminal to the whole group when we're interactive, so
184
+ // forward those only when not attached to a terminal.
185
+ return interactive ? ["SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
186
+ }
187
+
188
+ function runEngine(vpy, args, wheel) {
189
+ // Lets `schedule add` reuse this exact wheel for the root-owned engine.
190
+ const env = Object.assign({}, process.env);
191
+ if (wheel) env.WHATSRUNNING_WHEEL = wheel;
192
+ const child = spawn(vpy, ["-m", "whatsrunning", ...args], { stdio: "inherit", env });
193
+
194
+ const interactive = Boolean(process.stdin.isTTY);
195
+ const forwarded = forwardedSignals(process.platform, interactive);
196
+ const handlers = {};
197
+ for (const sig of forwarded) {
198
+ handlers[sig] = () => {
199
+ try { child.kill(sig); } catch (e) { /* already gone */ }
200
+ };
201
+ }
202
+ // Signals we don't forward must still not kill the launcher before the
203
+ // engine is done (it's restoring the network); keep a no-op handler.
204
+ const all = process.platform === "win32" ? ["SIGINT", "SIGBREAK", "SIGHUP"]
205
+ : ["SIGINT", "SIGTERM", "SIGHUP"];
206
+ for (const sig of all) {
207
+ if (!handlers[sig]) handlers[sig] = () => {};
208
+ }
209
+ for (const sig of Object.keys(handlers)) {
210
+ try { process.on(sig, handlers[sig]); } catch (e) { /* unsupported here */ }
211
+ }
212
+
213
+ child.on("error", (e) => {
214
+ log(`could not start the engine: ${e.message}`);
215
+ process.exit(1);
216
+ });
217
+ child.on("exit", (code, signal) => {
218
+ for (const sig of Object.keys(handlers)) process.removeListener(sig, handlers[sig]);
219
+ if (signal) {
220
+ // Die the same way the engine did, so callers see the real reason.
221
+ try { process.kill(process.pid, signal); } catch (e) { /* fall through */ }
222
+ process.exit(1);
223
+ }
224
+ process.exit(code === null ? 1 : code);
225
+ });
226
+ }
227
+
228
+ module.exports = { forwardedSignals, runEngine };
229
+
230
+ if (require.main === module) main();
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "whatsrunning",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.6.0",
4
+ "description": "See what every device on your own home network is talking to. (npm launcher for the Python engine.)",
5
+ "bin": {
6
+ "whatsrunning": "bin/whatsrunning.js"
7
+ },
8
+ "files": [
9
+ "bin/",
10
+ "vendor/",
11
+ "README.md"
12
+ ],
13
+ "keywords": [
14
+ "network",
15
+ "monitoring",
16
+ "privacy",
17
+ "dns",
18
+ "security",
19
+ "home-network",
20
+ "packets"
21
+ ],
22
+ "homepage": "https://github.com/dmoney25632/whatsrunning",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/dmoney25632/whatsrunning.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/dmoney25632/whatsrunning/issues"
29
+ },
30
+ "license": "MIT",
31
+ "engines": {
32
+ "node": ">=14"
33
+ },
34
+ "os": [
35
+ "darwin",
36
+ "linux",
37
+ "win32"
38
+ ],
39
+ "preferGlobal": true
40
+ }