windscout 0.6.4 → 0.7.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,8 +1,8 @@
1
1
  # WindScout
2
2
 
3
- Find which Windscribe locations and protocols actually work from your network, ranked by latency. Runs on Linux, macOS and Windows.
3
+ Find which Windscribe locations and protocols actually work from your network, ranked by speed. Runs on Linux, macOS and Windows.
4
4
 
5
- WindScout drives the official `windscribe-cli`: it connects to each country × protocol pair, measures latency through the tunnel, disconnects, and prints a ranked table.
5
+ WindScout drives the official `windscribe-cli`: it connects to each country × protocol pair, measures latency and download speed through the tunnel, disconnects, and prints a ranked table.
6
6
 
7
7
  ![WindScout picking countries, scanning, and printing the availability grid and ranked results](demo.gif)
8
8
 
@@ -23,6 +23,57 @@ npm install -g windscout # or run once with: npx windscout
23
23
 
24
24
  On startup, WindScout checks npm for a newer version. Above the repository link at the bottom of the screen, it shows the installed version in grey (`windscout 0.5.6 · latest` once npm confirms nothing newer is out), or, when a newer one is out, an update notice in yellow. In the picker, press `u` to update and restart on the new version. The update runs `npm install -g windscout@latest`, with `sudo` when your global npm folder belongs to root (sudo then asks for your password). The update command is also printed after the final report.
25
25
 
26
+ ### In a sandbox (Docker)
27
+
28
+ To run WindScout without installing it or Node on your computer, run it in a container. The container has its own Windscribe app (Windscribe's Linux CLI app) and, for [parallel scans](#parallel-scan-with-docker), its own docker daemon inside it (Docker-in-Docker). You need Docker: on Linux, docker itself; on macOS and Windows, [Docker Desktop](https://docs.docker.com/desktop/) (on Windows with its WSL 2 engine, set to Linux containers). Build the image once, the same way on every system. Docker fetches this repository from GitHub itself, so there's nothing to clone (add `#` and a branch, tag or commit to the URL to build that one, as in `windscout.git#main`; in a clone, use `.` in place of the URL to build your copy):
29
+
30
+ ```sh
31
+ docker build -t windscout-sandbox -f sandbox/Dockerfile https://github.com/Diercohen/windscout.git
32
+ ```
33
+
34
+ Then run it with the command for your system, below. If the Windscribe app on your computer is logged in, the container's app logs in with that app's session, as the [parallel scan's containers](#parallel-scan-with-docker) do: the command hands it to the container in a file mounted read-only, and the container copies only the session (`userId` and `authHash`) into its own app's settings. Without the app, or when its session doesn't work, the container asks for your Windscribe username and password (and 2FA code, if you use one), and the `windscout-home` volume keeps that login for the next runs. Then the picker opens as usual. Options after the image name go to WindScout: `windscout-sandbox -c "DE,NL" -d`. The `windscout-docker` volume keeps the inner docker's `windscout-worker` image and its containers' volumes, so only the first parallel scan builds them.
35
+
36
+ **Linux:** the app's settings file is mounted as it is (read-only, never changed). Without the Windscribe app, leave out the `Windscribe2.conf` line: otherwise docker creates an empty folder in its place.
37
+
38
+ ```sh
39
+ docker run -it --rm --privileged \
40
+ -v ~/.config/Windscribe/Windscribe2.conf:/host/Windscribe2.conf:ro \
41
+ -v windscout-home:/home/ws -v windscout-docker:/var/lib/docker \
42
+ windscout-sandbox
43
+ ```
44
+
45
+ **macOS** (Terminal): the app keeps its session in its defaults, so the first line writes it to a private temporary file, which the last line deletes after the run.
46
+
47
+ ```sh
48
+ s=$(mktemp) && printf '[General]\nuserId=%s\nauthHash=%s\n' "$(defaults read com.windscribe.Windscribe2 userId)" "$(defaults read com.windscribe.Windscribe2 authHash)" > "$s"
49
+ docker run -it --rm --privileged \
50
+ -v "$s:/host/Windscribe2.conf:ro" \
51
+ -v windscout-home:/home/ws -v windscout-docker:/var/lib/docker \
52
+ windscout-sandbox
53
+ rm -f "$s"
54
+ ```
55
+
56
+ **Windows** (PowerShell): the app keeps its session in the registry, so the first lines write it to a private temporary file, which the last line deletes after the run.
57
+
58
+ ```powershell
59
+ $k = Get-ItemProperty HKCU:\Software\Windscribe\Windscribe2
60
+ $s = New-TemporaryFile
61
+ Set-Content $s "[General]`nuserId=$($k.userId)`nauthHash=$($k.authHash)"
62
+ docker run -it --rm --privileged `
63
+ -v "$($s.FullName):/host/Windscribe2.conf:ro" `
64
+ -v windscout-home:/home/ws -v windscout-docker:/var/lib/docker `
65
+ windscout-sandbox
66
+ Remove-Item $s
67
+ ```
68
+
69
+ Without the Windscribe app on macOS or Windows, run only the `docker run` command, without its `Windscribe2.conf` line.
70
+
71
+ - `--privileged` is needed: the inner docker, and the Windscribe app's tunnel and firewall, need it. It gives the container broad control of docker's Linux kernel (on Linux, your computer's), so this isolates files and installs, not security. VPN connections stay inside the container: your computer's own connection doesn't change.
72
+ - Docker Desktop's own Linux VM (macOS, Windows without WSL 2) can't run Windscribe's WireGuard (see the kernel check under [parallel scans](#parallel-scan-with-docker)), and in the sandbox that goes for its own app too. Windscribe's Linux app has no IKEv2, so the sandbox doesn't try it.
73
+ - Where Docker Hub refuses (Iran), take the base image from a mirror: `docker build --build-arg BASE=registry.docker.ir/library/node:22-bookworm-slim -t windscout-sandbox -f sandbox/Dockerfile https://github.com/Diercohen/windscout.git`
74
+ - Updating from inside (`u`) doesn't last, since each run starts fresh from the image: run the build command again instead, for the latest WindScout; add `--no-cache` to get the latest Windscribe app too.
75
+ - To remove everything: `docker rmi windscout-sandbox` and `docker volume rm windscout-home windscout-docker`.
76
+
26
77
  ## Usage
27
78
 
28
79
  Run `windscout` with no arguments to open the interactive picker:
@@ -30,7 +81,7 @@ Run `windscout` with no arguments to open the interactive picker:
30
81
  ```
31
82
  ╭─ WindScout ──────────────────────────────────── 2/68 selected ─╮
32
83
  │ 1 ● wireguard 2 ● stealth 3 ○ wstunnel 4 ● udp 5 ● tcp │
33
- │ p ○ all ports off: each protocol on its default port │
84
+ │ s ○ speed test off: connect-only, ranks by latency │
34
85
  ╰────────────────────────────────────────────────────────────────╯
35
86
  ╭────────────────────────────────────────────────────────────────╮
36
87
  │ 🔍 an▏ 1–16 of 18 │
@@ -52,18 +103,20 @@ Run `windscout` with no arguments to open the interactive picker:
52
103
  | `a` / `n` | select all / unselect all (only the matching countries while a search is active) |
53
104
  | `1`–`6` | toggle a protocol (`1`–`5` on Linux, which has no IKEv2) |
54
105
  | `p` | toggle [all ports](#all-ports): each protocol on every port it has, not just its default |
106
+ | `s` | toggle the speed test (off = connect-only mode) |
55
107
  | `f` | toggle "block internet while scanning" (firewall) |
56
- | `r` | toggle random order: scan the selected countries shuffled, a new order each run |
57
108
  | `d` | toggle the [parallel scan in docker containers](#parallel-scan-with-docker) (installs or starts docker first, after asking) |
109
+ | `o` | change the [scanning type](#scanning-type): default, by random country, by last success result first, only the last results |
110
+ | `w` | toggle [stop at the first working connection](#stop-at-the-first-working-connection) that holds up |
58
111
  | `u` | update to the newer version and restart (only when the picker shows one is out) |
59
112
  | `enter` | start scanning |
60
113
  | `q` | quit (during a scan: stop and show partial results; press again to force quit) |
61
114
 
62
- **Mouse:** click a country to select or unselect it, click a protocol or a setting's line to toggle it, click the search box to start typing (click anywhere else to leave it), and scroll the list with the wheel. The `[ ▶ Start ] [ All ] [ None ] [ Quit ]` buttons under the table do the same as their keys; the shortcut key is underlined on screen (on the buttons, the protocol numbers and the settings' letters). This needs a terminal with mouse support, which most have. On Windows, use Windows Terminal; if clicks do nothing there, the keyboard does everything.
115
+ **Mouse:** click a country to select or unselect it, click a protocol or a setting's line to toggle it (the scanning type's line changes the type), click the search box to start typing (click anywhere else to leave it), and scroll the list with the wheel. The `[ ▶ Start ] [ All ] [ None ] [ Quit ]` buttons under the table do the same as their keys; the shortcut key is underlined on screen (on the buttons, the protocol numbers and `s`). This needs a terminal with mouse support, which most have. On Windows, use Windows Terminal; if clicks do nothing there, the keyboard does everything.
63
116
 
64
117
  Your selection is saved to `~/.config/windscout/config.json` (`%USERPROFILE%\.config\windscout\config.json` on Windows) and preselected next time.
65
118
 
66
- While scanning, WindScout shows a progress bar, elapsed time and remaining time. It also shows what it's doing right now (connecting or measuring latency). The table of working locations refreshes after each country. When the scan finishes, the final report is printed to your normal terminal. It ends with the best connection and the other working ones, each with its `windscribe-cli connect` command. At the prompt, press enter to connect to the best one, type another one's number to connect to that, or `q` to quit.
119
+ After you start, the Start button spins (`[ ⠋ Starting… ]`) until the scan's screen shows, which can take a moment when it turns the firewall on or starts docker. While scanning, WindScout shows a progress bar, elapsed time and remaining time. It also shows what it's doing right now (connecting, measuring latency or measuring speed). The table of working locations refreshes after each country. When the scan finishes, the final report is printed to your normal terminal. It ends with the best connection and the other working ones, each with its `windscribe-cli connect` command. At the prompt, press enter to connect to the best one, type another one's number to connect to that, or `q` to quit.
67
120
 
68
121
  ### Non-interactive
69
122
 
@@ -83,14 +136,54 @@ windscout -t 40 -a # longer connect timeout, also list
83
136
  | `-P, --all-ports` | try each protocol on [every port](#all-ports) Windscribe offers for it, not just its default | picker: saved, or off; with `-c`: off |
84
137
  | `-t, --timeout` | seconds to wait for each connection, at least 10 | picker: saved, or 15; with `-c`: 15 |
85
138
  | `-a, --all` | include failed attempts in the final table | off |
139
+ | `-n, --no-speed` | connect-only mode: skip the download test, rank by latency | picker: saved, or connect-only on first run; with `-c`: speed test on |
86
140
  | `-f, --firewall` | block internet while scanning, except through the VPN | picker: saved, or off; with `-c`: off |
87
- | `-r, --random` | scan the countries in a random order | picker: saved, or off; with `-c`: off |
141
+ | `-o, --order` | [scanning type](#scanning-type): `default`, `random`, `last-first` or `last-only` (`-r` still works: the same as `-o random`) | picker: saved, or `default`; with `-c`: `default` |
142
+ | `-w, --stop-at-first` | [stop at the first working connection](#stop-at-the-first-working-connection) that holds up | picker: saved, or off; with `-c`: off |
88
143
  | `-d, --docker` | [scan in parallel, in docker containers](#parallel-scan-with-docker) | picker: saved, or off; with `-c`: off |
89
144
  | `-v, --version` | print the installed version; if a newer one is on npm, show the update command (with `sudo` when needed) and ask (y/n) to run it | |
90
145
 
91
- ## Availability grid
146
+ ## Last result: rescan and connect
147
+
148
+ After each scan, WindScout saves its working connections, best first, to `~/.config/windscout/last.json`. That includes a partial scan you stopped, and a scan started with `-c`. A scan's working connections replace the saved ones it tried, so the ones that stopped working drop out. The saved connections it didn't try stay, after its own: those of countries it didn't scan, and what a stopped scan didn't get to. A scan where nothing worked keeps the previous result as it is, since the network may just be down.
149
+
150
+ - **Rescan:** the [scanning types](#scanning-type) *by last success result first* and *only the last results* use the saved connections: the first tries the ones in your selection before the rest of it, the second tries only them.
151
+ - **Connect:** `windscout connect` connects to the best saved connection, without a scan. It checks each as the scan does: when one doesn't connect within the timeout (`-t`, or the saved one), or has no internet through it, it tries the next, until one connects. When none does, or there's no saved scan, it says so and suggests a rescan or a new scan.
152
+
153
+ ```sh
154
+ windscout connect # the best saved connection that still works
155
+ windscout connect -t 30 # wait longer for each
156
+ ```
157
+
158
+ ## Scanning type
159
+
160
+ Press `o` in the picker, or pass `-o`, to choose what a scan tries and in which order. The picker's line shows the type, and the estimate under the table counts what that type scans. The type is remembered with your other settings.
161
+
162
+ | Type | `-o` | What it scans |
163
+ |---|---|---|
164
+ | default | `default` | the selected countries × protocols, the countries in list order |
165
+ | by random country | `random` | the same, with the countries shuffled, a new order each run |
166
+ | by last success result first | `last-first` | the same, but the [last result](#last-result-rescan-and-connect)'s working connections among them go first, best first and on their own port, then the rest. With one country selected, only that country is scanned, its saved connections first. The line shows how many saved connections are in your selection (`1 of 7 saved selected · 3h ago`) |
167
+ | only the last results | `last-only` | only the last result's working connections, each on its own protocol and port. The countries, protocols and all ports are skipped, so the picker greys them out and locks them (your selection stays for next time). With `-o last-only`, `-c` isn't needed |
168
+
169
+ The two types by the last result need a saved scan. Until there is one, choosing either turns `[ ▶ Start ]` off (greyed out), and a warning takes the estimate's place: `no saved scan yet, so start is off: press o for another scanning type`. Without the picker, `-o last-first` and `-o last-only` stop with an error instead. The estimate counts each saved connection once: `tcp` and `tcp:443` are the same attempt when 443 is tcp's default port.
170
+
171
+ ### Stop at the first working connection
172
+
173
+ Press `w` in the picker, or pass `-w`, to end the scan at the first connection that works and holds up: the attempts still connecting give up, and no more start. The scan stops at one connection, so that one has to be good for long use. A tunnel can connect and then be cut or throttled once traffic flows, so each connection that connects is checked first:
174
+
175
+ 1. A speed test, even with the speed test off (`s`, `-n`). It must reach at least 1 Mbps.
176
+ 2. Then it has to stay connected, with internet through it, for 5 round trips 2 s apart (about 10 s), each round trip allowed one retry.
177
+
178
+ A connection that drops during the check gets the status `unreliable` and doesn't count as working: it isn't saved, or offered to connect to. One that stays up but is slower than 1 Mbps still counts as working, but the scan doesn't stop there and keeps looking. If nothing passes, the scan runs to the end, and the report shows whatever worked.
179
+
180
+ The check adds up to about 30 s to each connection that connects (the speed test alone takes up to 15 s). The estimate reads `up to N attempts · at most ≈ …`, for when none holds up. With a type by the last result, the best saved connection goes first, and the line shows about how long the scan takes if it still holds up (`≈ 33s if DE stealth still holds up`). It's the quickest way back online: *only the last results* or *by last success result first*, with `w`.
181
+
182
+ ## Connect-only mode
183
+
184
+ Often you only need to know **what connects**, not how fast it is. Turn the speed test off with `s` in the picker or with `--no-speed`. Each working connection is then checked with a quick latency test only. That saves about 15 s per working connection, and results are ranked by latency. Connect-only is the default on the first run, and the choice is remembered.
92
185
 
93
- Each working connection gets a quick latency test, and the working ones are ranked by latency. The scan screen and the final report show an **availability grid**: one row per country, and ✓ / ✗ for each protocol (`·` = not tried yet; `key limit`, in a [parallel scan](#parallel-scan-with-docker): WireGuard couldn't be tried). With [all ports](#all-ports), it counts how many of a protocol's ports worked: `✓ 3/11`. Location(s) lists each datacenter that connected, one per line, since protocols can land on different ones:
186
+ Both modes show an **availability grid**: one row per country, and ✓ / ✗ for each protocol (`·` = not tried yet; `key limit`, in a [parallel scan](#parallel-scan-with-docker): WireGuard couldn't be tried). With [all ports](#all-ports), it counts how many of a protocol's ports worked: `✓ 3/11`. Location(s) lists each datacenter that connected, one per line, since protocols can land on different ones:
94
187
 
95
188
  ```
96
189
  ╭──────────────────────────────────────────────────────────────────────────────╮
@@ -105,7 +198,7 @@ Each working connection gets a quick latency test, and the working ones are rank
105
198
  ╰─────────────────────────┴────────────────────────┴─────────┴───────────┴─────╯
106
199
  ```
107
200
 
108
- While scanning, press `tab` to switch between the availability grid and the latency ranking. Press `p` (or `space`) to pause: the current attempt finishes, the VPN disconnects, and the scan waits until you press `p` again. Paused time doesn't count toward elapsed or remaining. The scan starts on the availability grid.
201
+ While scanning, press `tab` to switch between the availability grid and the speed or latency ranking. Press `p` (or `space`) to pause: the current attempt finishes, the VPN disconnects, and the scan waits until you press `p` again. Paused time doesn't count toward elapsed or remaining. In connect-only mode the scan starts on the availability grid.
109
202
 
110
203
  ## All ports
111
204
 
@@ -119,7 +212,7 @@ Each protocol is normally tried on its default port, the first one Windscribe li
119
212
  | udp | 443, 80, 53, 123, 1194, 54783 | 6 |
120
213
  | tcp | 443, 587, 21, 22, 80, 123, 143, 3306, 8080, 54783, 1194 | 11 |
121
214
 
122
- With every protocol selected, that's 35 attempts per country instead of 5, 7 times as many (on macOS and Windows, IKEv2 adds its own ports). The picker shows the count (`35 attempts per country, not 5`) and the estimate: one country takes about 11m 40s instead of 1m 40s in a normal scan, and about 2 minutes in a [parallel scan](#parallel-scan-with-docker), which helps most here. To try fewer, select only the protocols you need, or give a port yourself: a protocol with a port (`-p tcp:443`) stays on that one.
215
+ With every protocol selected, that's 35 attempts per country instead of 5, 7 times as many (on macOS and Windows, IKEv2 adds its own ports). The picker shows the count (`35 attempts per country, not 5`) and the estimate: one country takes about 11m 40s instead of 1m 40s in a normal scan, and about 2 minutes in a [parallel scan](#parallel-scan-with-docker), which helps most here. With the speed test on, every working port gets a speed test too, about 15 s each, so connect-only mode finds the working ports sooner. To try fewer, select only the protocols you need, or give a port yourself: a protocol with a port (`-p tcp:443`) stays on that one.
123
216
 
124
217
  The availability grid keeps one column per protocol and counts how many of its ports worked (`✓ 3/11`, or `✗ 0/11` when none did). The results list each working protocol with its port, and the per-protocol table has a line per port.
125
218
 
@@ -163,7 +256,7 @@ The mirrors come from [Mirava](https://github.com/MiravaOrg/Mirava)'s list of mi
163
256
 
164
257
  WindScout 0.6.0 asked for your username and password instead, and could save them in `~/.config/windscout/login.json`. WindScout now deletes that file.
165
258
 
166
- **Measuring:** the containers share your internet connection, so they take turns measuring latency while the connecting happens in parallel. Numbers stay comparable with a normal scan. Most of the time saved comes from attempts that hang until the timeout, which overlap now.
259
+ **Measuring:** the containers share your internet connection, so they take turns measuring latency and speed while the connecting happens in parallel. Numbers stay comparable with a normal scan. Most of the time saved comes from attempts that hang until the timeout, which overlap now.
167
260
 
168
261
  **Differences from a normal scan:**
169
262
 
@@ -183,23 +276,23 @@ While scanning:
183
276
  │ ██████████████████████████████████████████▌░░░░░░░░░░░░░░░░ 72% │
184
277
  │ │
185
278
  │ ⠏ 🇳🇱 Netherlands · stealth │
186
- │ measuring latency · Amsterdam - Tulip · 1s │
279
+ │ measuring speed · Amsterdam - Tulip · 3s │
187
280
  ├──────────────────────────────────────────────────────────────────────┤
188
281
  │ elapsed 25s │ remaining ≈ 13s │ ✓ 2 working │ ✗ 1 blocked │
189
282
  ╰──────────────────────────────────────────────────────────────────────╯
190
283
  ╭──────────────────────────────────────────────────────────────────────╮
191
284
  │ Working so far 2 found │
192
285
  ├───┬────────────┬───────────────────────┬───────────┬───────────┬─────┤
193
- │ # │ Country │ Location │ Protocol │ Latency │ ... │
286
+ │ # │ Country │ Location │ Protocol │ Speed │ ... │
194
287
  ```
195
288
 
196
289
  At the end, the results, a per-protocol summary and the best pick are printed to your normal terminal:
197
290
 
198
291
  ```
199
- ╭─ ★ Best (lowest latency) ────────────────────╮
200
- │ 🇳🇱 Amsterdam - Tulip over wireguard · 109 ms │
201
- │ windscribe-cli connect "Tulip" wireguard │
202
- ╰──────────────────────────────────────────────╯
292
+ ╭─ ★ Best ─────────────────────────────────────────────────╮
293
+ │ 🇳🇱 Amsterdam - Tulip over wireguard · 27.0 Mbps · 109 ms │
294
+ │ windscribe-cli connect "Tulip" wireguard │
295
+ ╰──────────────────────────────────────────────────────────╯
203
296
  ```
204
297
 
205
298
  ## Notes
package/dist/cli.js CHANGED
@@ -1,28 +1,31 @@
1
1
  #!/usr/bin/env node
2
2
  // WindScout: find which Windscribe locations and protocols actually work from here.
3
3
  // Drives the official windscribe-cli: connects to each country/protocol pair,
4
- // measures latency through the tunnel, prints a ranked table.
4
+ // measures latency and download speed through the tunnel, prints a ranked table.
5
5
  import { createInterface } from "node:readline";
6
6
  import { spawnSync } from "node:child_process";
7
7
  import { parseArgs } from "node:util";
8
- import { CONFIG, DEFAULT_TIMEOUT, forgetLogin, loadConfig, loadDockerWireGuard, MIN_TIMEOUT, saveDockerWireGuard, SPEED_TEST } from "./config.js";
8
+ import { CONFIG, DEFAULT_TIMEOUT, forgetLogin, LAST_FILE, loadConfig, loadDockerWireGuard, loadLast, MIN_TIMEOUT, saveDockerWireGuard, saveLast, SPEED_TEST } from "./config.js";
9
9
  import { notInContainers, stopWorkers } from "./docker.js";
10
- import { probe } from "./probe.js";
11
- import { Scan } from "./scan.js";
10
+ import { attempt, disconnect, MIN_MBPS, probe } from "./probe.js";
11
+ import { ORDERS, plan, Scan } from "./scan.js";
12
12
  import { startParallel } from "./tui/docker.js";
13
13
  import { pick } from "./tui/picker.js";
14
14
  import { logProgress, showProgress } from "./tui/progress.js";
15
15
  import { command, report, target } from "./tui/report.js";
16
16
  import { leaveScreen, out } from "./tui/terminal.js";
17
17
  import { cyan, green, yellow } from "./tui/text.js";
18
- import { now, sleep } from "./time.js";
18
+ import { duration, now } from "./time.js";
19
19
  import { canUpdate, checkUpdate, runUpdate, updateNotice, versionLines } from "./update.js";
20
- import { blockInternet, CLI, connectState, isFirewallOn, protocolPorts, PROTOCOLS, restoreFirewall, waitForLogin, windscribe, withPorts } from "./windscribe.js";
20
+ import { blockInternet, CLI, isFirewallOn, protocolPorts, PROTOCOLS, restoreFirewall, waitForLogin, windscribe, withPorts } from "./windscribe.js";
21
21
  import { worker } from "./worker.js";
22
22
  const HELP = `Usage: windscout [options]
23
+ windscout connect [-t SEC]
23
24
 
24
25
  Find which Windscribe locations and protocols work from your network, ranked by ${SPEED_TEST ? "speed" : "latency"}.
25
26
  Without -c it opens an interactive country picker (your selection is remembered).
27
+ Each scan's working connections are saved: the scanning type (-o, or o in the picker) can try
28
+ them first or only them, and windscout connect connects to the best of them that still works.
26
29
 
27
30
  Options:
28
31
  -c, --countries LIST comma-separated ISO codes, city names or nicknames (skips the picker)
@@ -31,14 +34,19 @@ Options:
31
34
  -t, --timeout SEC seconds to wait for each connection, at least ${MIN_TIMEOUT} (default: saved, or ${DEFAULT_TIMEOUT})
32
35
  -a, --all also show failed attempts in the final table
33
36
  ${SPEED_TEST ? " -n, --no-speed connect-only: skip the download test, rank by latency (faster scan)\n" : ""} -f, --firewall block internet while scanning, except through the VPN (turned back off afterwards)
34
- -r, --random scan the countries in a random order
37
+ -o, --order TYPE scanning type: default (list order), random (countries shuffled), last-first (the last
38
+ result's working connections among them first, then the rest) or last-only (only those,
39
+ whatever -c and -p say; needs no -c)
40
+ -w, --stop-at-first stop at the first working connection that holds up: a speed test (even with -n) of at least
41
+ ${MIN_MBPS} Mbps, then about 10 more seconds connected, with internet through it
35
42
  -d, --docker scan in parallel, in docker containers (one per attempt, up to 16, as docker's CPUs and memory allow)
36
43
  -v, --version show the installed version (and offer to update if a newer one is out)
37
44
  -h, --help show this help
38
45
 
39
- Selection is stored in ${CONFIG}
46
+ Selection is stored in ${CONFIG}, the last result in ${LAST_FILE}
40
47
  Examples: windscout -c DE,NL,TR -p stealth,tcp:443
41
- windscout -c DE -p stealth,tcp -P`;
48
+ windscout -c DE -p stealth,tcp -P
49
+ windscout connect`;
42
50
  // "DE, NL,,TR" → ["DE", "NL", "TR"]
43
51
  const list = (s) => s.split(",").map((x) => x.trim()).filter(Boolean);
44
52
  const ask = (question) => new Promise((resolve) => {
@@ -47,6 +55,17 @@ const ask = (question) => new Promise((resolve) => {
47
55
  rl.on("close", () => resolve(null));
48
56
  rl.question(question, (a) => (resolve(a.trim()), rl.close()));
49
57
  });
58
+ /** Runs a result's connect command and checks it as the scan does: connected, on its port, with internet through it.
59
+ * True once it is; otherwise disconnects (and waits until the app has), so the next connect isn't swallowed */
60
+ async function connectTo(r, timeout) {
61
+ console.log(cyan(command(r)));
62
+ const t = now(), { status, location } = await attempt(target(r), r.protocol, { timeout, speedTest: false });
63
+ if (status === "ok")
64
+ return console.log(green(`Connected: ${location}`)), true;
65
+ console.log(yellow(`${status} after ${duration(now() - t)}`));
66
+ await disconnect();
67
+ return false;
68
+ }
50
69
  /** Asks which numbered connection to make (enter: the best), then runs its command and waits for it to connect */
51
70
  async function offerConnect(choices, timeout) {
52
71
  const others = choices.length > 2 ? `, 1-${choices.length - 1} = other` : choices.length > 1 ? ", 1 = other" : "";
@@ -59,15 +78,29 @@ async function offerConnect(choices, timeout) {
59
78
  console.log(yellow(`no #${a} in the tables`));
60
79
  continue;
61
80
  }
62
- console.log(cyan(command(r)));
63
- await windscribe("connect", target(r), r.protocol);
64
- let state = "";
65
- for (const t = now(); now() - t < timeout && !(state = await connectState()).startsWith("Connected");)
66
- await sleep(1000);
67
- console.log(state.startsWith("Connected") ? green(state) : yellow(`${state || "not connected"} after ${timeout} s`));
81
+ await connectTo(r, timeout);
68
82
  return;
69
83
  }
70
84
  }
85
+ const RESCAN_HINT = "rescan them with windscout -o last-only, or start a new scan";
86
+ /** windscout connect: the last result's connections, best first, until one connects */
87
+ async function connectLast(timeout) {
88
+ const last = loadLast();
89
+ if (!last) {
90
+ console.log(yellow("no saved scan yet: run windscout to scan first"));
91
+ process.exitCode = 1;
92
+ return;
93
+ }
94
+ await waitForLogin();
95
+ await disconnect(); // a connection already up would read as the first one connecting
96
+ for (const [i, r] of last.results.entries()) {
97
+ console.log(`\n${i + 1}/${last.results.length} ${r.location || r.query} over ${r.protocol}`);
98
+ if (await connectTo(r, timeout))
99
+ return;
100
+ }
101
+ console.log(yellow(`\nnone of the last result's ${last.results.length} connection${last.results.length === 1 ? "" : "s"} works now: ${RESCAN_HINT}`));
102
+ process.exitCode = 1;
103
+ }
71
104
  /** u in the picker: update, then run the new version in this one's place, with the same arguments */
72
105
  function updateAndRestart() {
73
106
  const status = runUpdate();
@@ -80,7 +113,8 @@ function updateAndRestart() {
80
113
  process.exitCode = spawnSync(process.execPath, [...process.execArgv, ...process.argv.slice(1)], { stdio: "inherit" }).status ?? 1;
81
114
  }
82
115
  async function main() {
83
- const { values: a } = parseArgs({
116
+ const { values: a, positionals } = parseArgs({
117
+ allowPositionals: true,
84
118
  options: {
85
119
  countries: { type: "string", short: "c" },
86
120
  protocols: { type: "string", short: "p" },
@@ -89,9 +123,11 @@ async function main() {
89
123
  all: { type: "boolean", short: "a", default: false },
90
124
  help: { type: "boolean", short: "h", default: false },
91
125
  version: { type: "boolean", short: "v", default: false },
92
- "no-speed": { type: "boolean", short: "n", default: false }, // still accepted while the speed test is hidden
126
+ "no-speed": { type: "boolean", short: "n", default: false },
93
127
  firewall: { type: "boolean", short: "f", default: false },
94
- random: { type: "boolean", short: "r", default: false },
128
+ order: { type: "string", short: "o" },
129
+ "stop-at-first": { type: "boolean", short: "w", default: false },
130
+ random: { type: "boolean", short: "r", default: false }, // from before scanning types: -o random
95
131
  docker: { type: "boolean", short: "d", default: false },
96
132
  worker: { type: "boolean", default: false }, // in a parallel scan's container
97
133
  },
@@ -103,6 +139,11 @@ async function main() {
103
139
  forgetLogin();
104
140
  if (a.help)
105
141
  return console.log(HELP);
142
+ const [subcommand, ...extra] = positionals;
143
+ if (subcommand !== undefined && (subcommand !== "connect" || extra.length))
144
+ throw new Error(`unknown command '${positionals.join(" ")}': see --help`);
145
+ if (subcommand === "connect" && Object.entries(a).some(([k, v]) => k !== "timeout" && v))
146
+ throw new Error("windscout connect takes only -t: see --help");
106
147
  checkUpdate(); // runs while the app starts and the user picks, before the VPN starts switching
107
148
  if (a.version) {
108
149
  await checkUpdate();
@@ -114,16 +155,23 @@ async function main() {
114
155
  let timeout = a.timeout ? Number(a.timeout) : undefined;
115
156
  if (timeout !== undefined && !(timeout >= MIN_TIMEOUT))
116
157
  throw new Error(`--timeout must be at least ${MIN_TIMEOUT} seconds`);
158
+ if (a.order !== undefined && !ORDERS.includes(a.order))
159
+ throw new Error(`--order must be one of: ${ORDERS.join(", ")}`);
160
+ if (subcommand === "connect")
161
+ return connectLast(timeout ?? loadConfig()?.timeout ?? DEFAULT_TIMEOUT);
117
162
  const status = await waitForLogin();
118
163
  const tty = Boolean(process.stdin.isTTY && out.isTTY);
119
164
  let countries = a.countries ? list(a.countries) : undefined;
120
165
  let protocols = a.protocols ? list(a.protocols) : undefined;
121
166
  let speedTest = SPEED_TEST && !a["no-speed"];
122
167
  let firewall = a.firewall;
123
- let random = a.random;
168
+ let order = (a.order ?? (a.random ? "random" : undefined));
169
+ let stopAtFirst = a["stop-at-first"];
124
170
  let allPorts = a["all-ports"];
125
171
  let docker = a.docker;
126
- if (!countries) {
172
+ const last = loadLast();
173
+ // only the last results needs no countries: without a terminal, it goes without the picker
174
+ if (!countries && !(order === "last-only" && !tty)) {
127
175
  if (!tty)
128
176
  throw new Error("no terminal for the picker: pass countries with -c");
129
177
  const saved = loadConfig();
@@ -134,9 +182,11 @@ async function main() {
134
182
  speedTest: speedTest && (saved?.speed ?? false), // first run: connect-only
135
183
  // already on in the app: show it on, since the scan won't turn it off
136
184
  firewall: firewall || isFirewallOn(status) || (saved?.firewall ?? false),
137
- random: random || (saved?.random ?? false),
185
+ order: order ?? saved?.order ?? "default",
186
+ stopAtFirst: stopAtFirst || (saved?.stopAtFirst ?? false),
138
187
  allPorts: allPorts || (saved?.allPorts ?? false),
139
188
  docker: docker || (saved?.docker ?? false),
189
+ last,
140
190
  });
141
191
  if (!choice)
142
192
  return;
@@ -146,34 +196,41 @@ async function main() {
146
196
  protocols ??= choice.protocols;
147
197
  speedTest = choice.speed;
148
198
  firewall = choice.firewall;
149
- random = choice.random;
199
+ order = choice.order;
200
+ stopAtFirst = choice.stopAtFirst;
150
201
  allPorts = choice.allPorts;
151
202
  timeout = choice.timeout;
152
203
  docker = choice.docker;
153
204
  }
205
+ countries ??= [];
154
206
  protocols ??= PROTOCOLS;
155
207
  timeout ??= DEFAULT_TIMEOUT;
156
- // the picker asked for the ports already: waiting for that keeps windscribe-cli free for the scan
157
- if (allPorts || !a.countries) {
158
- const lists = await protocolPorts();
159
- if (allPorts)
160
- protocols = withPorts(protocols, lists);
161
- }
162
- if (random)
163
- countries = countries.map((c) => [Math.random(), c]).sort(([x], [y]) => x - y).map(([, c]) => c);
208
+ order ??= "default";
209
+ const byLast = order === "last-first" || order === "last-only"; // a type by the last result: it needs a saved scan
210
+ if (byLast && !last)
211
+ throw new Error(`no saved scan yet: -o ${order} needs one, so run a scan with another scanning type first`);
212
+ const fromLast = byLast ? last : null; // the saved connections this scan uses
213
+ // the picker asked for the ports already: waiting for that keeps windscribe-cli free for the scan.
214
+ // The saved connections need them too, to tell a saved "tcp:443" from tcp on its default port
215
+ const lists = allPorts || !a.countries || fromLast ? await protocolPorts() : undefined;
216
+ if (allPorts && lists)
217
+ protocols = withPorts(protocols, lists);
218
+ const attempts = plan(order, countries, protocols, fromLast?.results, lists);
219
+ // the tables' columns: the protocols asked for, and the saved connections' own (only those, when only they are scanned)
220
+ const scanned = [...new Set([...(order === "last-only" ? [] : protocols), ...attempts.map((x) => x.protocol)])];
164
221
  let probers = [probe], after; // after: what runs here once the containers are done
165
- const later = notInContainers(protocols, loadDockerWireGuard()); // as far as the last parallel scan knows
166
- const inContainers = countries.length * protocols.filter((p) => !later.has(p)).length;
222
+ const later = notInContainers(scanned, loadDockerWireGuard()); // as far as the last parallel scan knows
223
+ const inContainers = attempts.filter((x) => !later.has(x.protocol)).length;
167
224
  if (docker && inContainers) {
168
225
  const started = await startParallel(inContainers);
169
226
  if (!started)
170
227
  return leaveScreen();
171
228
  saveDockerWireGuard(started.wireguard);
172
229
  probers = started.probers;
173
- after = { prober: probe, protocols: notInContainers(protocols, started.wireguard), name: "this computer" };
230
+ after = { prober: probe, protocols: notInContainers(scanned, started.wireguard), name: "this computer" };
174
231
  await windscribe("disconnect"); // a VPN connection here would carry the containers' traffic too
175
232
  }
176
- const scan = new Scan(countries, protocols, { timeout, speedTest }, probers, after);
233
+ const scan = new Scan(countries, scanned, { timeout, speedTest, only: attempts, stopAtFirst }, probers, after);
177
234
  // not with containers: their traffic goes out through this computer, and the firewall would block it
178
235
  const blocking = firewall && !after && (await blockInternet());
179
236
  const view = tty ? showProgress(scan, blocking) : logProgress(scan);
@@ -184,9 +241,15 @@ async function main() {
184
241
  view.close();
185
242
  for (const e of new Set(scan.errors))
186
243
  console.error(yellow(e));
187
- if (scan.stopping)
244
+ if (scan.found)
245
+ console.log(green("stopped at the first connection that held up (a speed test, then staying up)"));
246
+ else if (scan.stopping)
188
247
  console.log(yellow("interrupted, showing partial results"));
189
- const choices = report(scan.results, protocols, { all: a.all, speedTest });
248
+ const choices = report(scan.results, scanned, { all: a.all, speedTest: speedTest || stopAtFirst }); // stop at the first measures speed
249
+ // its working connections replace the saved ones it tried, so what stopped working drops out; the saved ones it didn't try
250
+ // (other countries, or what a stopped scan didn't get to) stay, after its own; a scan where nothing worked keeps the last
251
+ const tried = new Set(scan.results.filter((r) => r.status !== "interrupted").map((r) => `${r.query} ${r.protocol}`));
252
+ saveLast(choices, undefined, tried);
190
253
  await checkUpdate();
191
254
  if (updateNotice())
192
255
  console.error("\n" + versionLines().join("\n"));
package/dist/config.js CHANGED
@@ -1,14 +1,16 @@
1
- // The picker's selection, and what the last parallel scan found its containers can do, remembered between runs.
1
+ // The picker's selection, what the last parallel scan found its containers can do, and the last scan's working results, remembered between runs.
2
2
  import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
+ import { ORDERS } from "./scan.js";
5
6
  import { COUNTRIES, PROTOCOLS } from "./windscribe.js";
6
- // The speed test is hidden: every scan is connect-only, and a saved "on" reads as off. Its code stays; true brings it back
7
- export const SPEED_TEST = false;
7
+ // false hides the speed test: every scan is connect-only, and a saved "on" reads as off
8
+ export const SPEED_TEST = true;
8
9
  export const DEFAULT_TIMEOUT = 15;
9
10
  export const MIN_TIMEOUT = 10; // seconds; shorter cuts off connections that would have worked
10
11
  export const CONFIG = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "windscout", "config.json");
11
12
  const DOCKER_FILE = join(dirname(CONFIG), "docker.json"); // what the last parallel scan found its containers can do
13
+ export const LAST_FILE = join(dirname(CONFIG), "last.json"); // the last scan's working connections
12
14
  /** The saved choice, minus anything this version doesn't offer; null on first run or an unreadable file */
13
15
  export function loadConfig() {
14
16
  try {
@@ -18,7 +20,8 @@ export function loadConfig() {
18
20
  protocols: (c.protocols ?? []).filter((x) => PROTOCOLS.includes(x)),
19
21
  speed: SPEED_TEST && c.speed !== false,
20
22
  firewall: c.firewall === true,
21
- random: c.random === true,
23
+ order: ORDERS.includes(c.order) ? c.order : c.random === true ? "random" : "default", // before scanning types: random on or off
24
+ stopAtFirst: c.stopAtFirst === true,
22
25
  allPorts: c.allPorts === true,
23
26
  timeout: c.timeout >= MIN_TIMEOUT ? c.timeout : DEFAULT_TIMEOUT,
24
27
  docker: c.docker === true,
@@ -51,6 +54,30 @@ export function saveDockerWireGuard(wireguard) {
51
54
  }
52
55
  catch { } // not being able to remember isn't worth failing the scan
53
56
  }
57
+ /** The last scan that found something; null when there's none or the file is unreadable */
58
+ export function loadLast() {
59
+ try {
60
+ const l = JSON.parse(readFileSync(LAST_FILE, "utf8"));
61
+ const results = (l.results ?? []).filter((r) => r?.status === "ok" && typeof r.query === "string" && typeof r.protocol === "string");
62
+ return results.length && typeof l.at === "number" ? { at: l.at, results } : null;
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ }
68
+ /** Saves a scan's working connections; a scan where nothing worked keeps the last one that found something (the network may
69
+ * just be down). With tried (the "query protocol" pairs the scan tried), the saved connections it didn't try stay, after its own */
70
+ export function saveLast(results, at = Date.now(), tried) {
71
+ if (!results.length)
72
+ return;
73
+ if (tried)
74
+ results = [...results, ...(loadLast()?.results ?? []).filter((r) => !tried.has(`${r.query} ${r.protocol}`))];
75
+ try {
76
+ mkdirSync(dirname(LAST_FILE), { recursive: true });
77
+ writeFileSync(LAST_FILE, JSON.stringify({ at, results }, null, 2) + "\n");
78
+ }
79
+ catch { } // not being able to remember isn't worth failing the scan
80
+ }
54
81
  /** Deletes the Windscribe username and password that 0.6.0 saved for the docker containers: they log in with this computer's session now */
55
82
  export function forgetLogin() {
56
83
  try {
package/dist/docker.js CHANGED
@@ -288,7 +288,7 @@ export async function startWorkers(n, session, onStatus) {
288
288
  };
289
289
  p.on("error", (e) => gone(e.message));
290
290
  p.on("close", (code) => gone(lastLine(err) || `exited (${code})`));
291
- const prober = (query, protocol, { timeout, speedTest, stopped = () => false, onStep = () => { } }) => new Promise((done, reject) => {
291
+ const prober = (query, protocol, { timeout, speedTest, steady = false, stopped = () => false, onStep = () => { } }) => new Promise((done, reject) => {
292
292
  if (dead)
293
293
  return reject(new Error(`container ${i + 1} stopped: ${dead}`));
294
294
  let leave = null, over = false;
@@ -311,7 +311,7 @@ export async function startWorkers(n, session, onStatus) {
311
311
  else if (m.result)
312
312
  end(), done(m.result);
313
313
  };
314
- send({ probe: { query, protocol, timeout, speedTest } });
314
+ send({ probe: { query, protocol, timeout, speedTest, steady } });
315
315
  });
316
316
  fail = (why) => (onStatus(`container ${i + 1}: ${why}`), resolve(null));
317
317
  on = (m) => {
package/dist/measure.js CHANGED
@@ -9,7 +9,7 @@ setDefaultAutoSelectFamily(false);
9
9
  setDefaultResultOrder("ipv4first");
10
10
  const LATENCY_URL = "https://www.gstatic.com/generate_204";
11
11
  const SPEED_URL = "https://speed.cloudflare.com/__down?bytes=10000000";
12
- const SPEED_SECONDS = 15;
12
+ export const SPEED_SECONDS = 15;
13
13
  /** Best round trip of a few tries, in ms; null if none got through */
14
14
  export async function latencyMs(tries = 3) {
15
15
  let best = null;