cfpilot 0.7.1 → 0.7.3

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/dist/cli.js CHANGED
@@ -1,12 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined") return require.apply(this, arguments);
8
- throw Error('Dynamic require of "' + x + '" is not supported');
9
- });
10
4
  var __esm = (fn, res) => function __init() {
11
5
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
6
  };
@@ -93,7 +87,7 @@ var VERSION, NAME;
93
87
  var init_version = __esm({
94
88
  "src/shared/version.ts"() {
95
89
  "use strict";
96
- VERSION = "0.7.1";
90
+ VERSION = "0.7.3";
97
91
  NAME = "cfpilot";
98
92
  }
99
93
  });
@@ -2803,7 +2797,9 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2803
2797
  let headerEnd = -1;
2804
2798
  let received = 0;
2805
2799
  let settled = false;
2806
- let buffer = "";
2800
+ let headerBuf = Buffer.alloc(0);
2801
+ let status2 = 0;
2802
+ const minPayload = Math.min(bytes, 32 * 1024);
2807
2803
  const finish = (result) => {
2808
2804
  if (settled) return;
2809
2805
  settled = true;
@@ -2814,11 +2810,21 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2814
2810
  }
2815
2811
  resolve2({ ...result, ms: Date.now() - started });
2816
2812
  };
2813
+ const judge = () => {
2814
+ if (status2 !== 200) {
2815
+ return { ok: false, error: status2 === 0 ? "\u672A\u6536\u5230\u54CD\u5E94\u5934" : `HTTP ${status2}` };
2816
+ }
2817
+ if (received < minPayload) {
2818
+ return { ok: false, error: `\u8F7D\u8377\u4E0D\u8DB3\uFF08${received}/${minPayload} \u5B57\u8282\uFF09` };
2819
+ }
2820
+ return { ok: true };
2821
+ };
2817
2822
  const request = [
2818
2823
  `GET ${path}?bytes=${bytes} HTTP/1.1`,
2819
2824
  `Host: ${host}`,
2820
2825
  `User-Agent: ${USER_AGENT}`,
2821
- `Accept: */*`,
2826
+ "Accept: */*",
2827
+ "Accept-Encoding: identity",
2822
2828
  "",
2823
2829
  ""
2824
2830
  ].join("\r\n");
@@ -2836,20 +2842,22 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2836
2842
  );
2837
2843
  const timer = setTimeout(() => {
2838
2844
  const seconds = Math.max(1e-3, (Date.now() - started) / 1e3);
2845
+ const v = judge();
2839
2846
  finish({
2840
- ok: received > 0,
2847
+ ok: v.ok,
2841
2848
  bytes: received,
2842
- speedMBps: received / 1024 / 1024 / seconds,
2843
- error: received > 0 ? void 0 : "\u6D4B\u901F\u8D85\u65F6"
2849
+ speedMBps: v.ok ? received / 1024 / 1024 / seconds : 0,
2850
+ error: v.ok ? void 0 : v.error ?? "\u4E0B\u8F7D\u8D85\u65F6"
2844
2851
  });
2845
2852
  }, timeoutMs);
2846
2853
  socket.setTimeout(timeoutMs, () => {
2847
2854
  const seconds = Math.max(1e-3, (Date.now() - started) / 1e3);
2855
+ const v = judge();
2848
2856
  finish({
2849
- ok: received > 0,
2857
+ ok: v.ok,
2850
2858
  bytes: received,
2851
- speedMBps: received / 1024 / 1024 / seconds,
2852
- error: received > 0 ? void 0 : "\u6D4B\u901F\u8D85\u65F6"
2859
+ speedMBps: v.ok ? received / 1024 / 1024 / seconds : 0,
2860
+ error: v.ok ? void 0 : v.error ?? "\u4E0B\u8F7D\u8D85\u65F6"
2853
2861
  });
2854
2862
  });
2855
2863
  socket.on("error", (err) => {
@@ -2858,20 +2866,34 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2858
2866
  const settle = () => {
2859
2867
  if (settled) return;
2860
2868
  const seconds = Math.max(1e-3, (Date.now() - started) / 1e3);
2861
- finish({ ok: received > 0, bytes: received, speedMBps: received / 1024 / 1024 / seconds });
2869
+ const v = judge();
2870
+ finish({
2871
+ ok: v.ok,
2872
+ bytes: received,
2873
+ speedMBps: v.ok ? received / 1024 / 1024 / seconds : 0,
2874
+ error: v.ok ? void 0 : v.error ?? "\u672A\u6536\u5230\u5B8C\u6574\u54CD\u5E94"
2875
+ });
2862
2876
  };
2863
2877
  socket.on("data", (chunk) => {
2864
2878
  if (headerEnd < 0) {
2865
- buffer += chunk.toString("latin1");
2866
- const idx = buffer.indexOf("\r\n\r\n");
2879
+ headerBuf = headerBuf.length === 0 ? chunk : Buffer.concat([headerBuf, chunk]);
2880
+ const idx = headerBuf.indexOf("\r\n\r\n");
2867
2881
  if (idx < 0) {
2868
- if (buffer.length > 8192) finish({ ok: false, bytes: 0, speedMBps: 0, error: "\u54CD\u5E94\u5934\u5F02\u5E38" });
2882
+ if (headerBuf.length > 8192) finish({ ok: false, bytes: 0, speedMBps: 0, error: "\u54CD\u5E94\u5934\u5F02\u5E38" });
2883
+ return;
2884
+ }
2885
+ const head = headerBuf.subarray(0, idx).toString("latin1");
2886
+ const code = /^HTTP\/1\.[01]\s+(\d{3})/.exec(head)?.[1];
2887
+ status2 = code ? Number(code) : 0;
2888
+ if (status2 !== 200) {
2889
+ finish({ ok: false, bytes: 0, speedMBps: 0, error: `HTTP ${status2 || "?"}` });
2869
2890
  return;
2870
2891
  }
2871
2892
  headerEnd = idx + 4;
2872
- const body = Buffer.from(buffer, "latin1").subarray(headerEnd);
2893
+ const body = headerBuf.subarray(headerEnd);
2873
2894
  received += body.byteLength;
2874
2895
  headerEnd = 0;
2896
+ headerBuf = Buffer.alloc(0);
2875
2897
  } else {
2876
2898
  received += chunk.byteLength;
2877
2899
  }
@@ -2947,7 +2969,7 @@ function measureThroughput(options) {
2947
2969
  ].join("\r\n");
2948
2970
  const openOne = () => {
2949
2971
  let headerDone = false;
2950
- let headerBuffer = "";
2972
+ let headerBuffer = Buffer.alloc(0);
2951
2973
  const socket = tls.connect(
2952
2974
  {
2953
2975
  host: ip,
@@ -2973,7 +2995,7 @@ function measureThroughput(options) {
2973
2995
  });
2974
2996
  socket.on("data", (chunk) => {
2975
2997
  if (!headerDone) {
2976
- headerBuffer += chunk.toString("latin1");
2998
+ headerBuffer = headerBuffer.length === 0 ? chunk : Buffer.concat([headerBuffer, chunk]);
2977
2999
  const idx = headerBuffer.indexOf("\r\n\r\n");
2978
3000
  if (idx < 0) {
2979
3001
  if (headerBuffer.length > 8192) {
@@ -2982,7 +3004,7 @@ function measureThroughput(options) {
2982
3004
  }
2983
3005
  return;
2984
3006
  }
2985
- const head = headerBuffer.slice(0, idx);
3007
+ const head = headerBuffer.subarray(0, idx).toString("latin1");
2986
3008
  const status2 = /^HTTP\/1\.[01]\s+(\d{3})/.exec(head)?.[1];
2987
3009
  if (status2 !== "200") {
2988
3010
  lastError = `HTTP ${status2 ?? "?"}`;
@@ -2990,10 +3012,10 @@ function measureThroughput(options) {
2990
3012
  return;
2991
3013
  }
2992
3014
  headerDone = true;
2993
- const body = Buffer.from(headerBuffer, "latin1").subarray(idx + 4);
3015
+ const body = headerBuffer.subarray(idx + 4);
2994
3016
  totalBytes += body.byteLength;
2995
3017
  windowBytes += body.byteLength;
2996
- headerBuffer = "";
3018
+ headerBuffer = Buffer.alloc(0);
2997
3019
  } else {
2998
3020
  totalBytes += chunk.byteLength;
2999
3021
  windowBytes += chunk.byteLength;
@@ -3028,12 +3050,13 @@ var USER_AGENT;
3028
3050
  var init_true_probe = __esm({
3029
3051
  "src/scan/true-probe.ts"() {
3030
3052
  "use strict";
3031
- USER_AGENT = "CFPilot-Scanner/1.0 (+https://github.com/xmwengxing/CFPilot)";
3053
+ USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
3032
3054
  }
3033
3055
  });
3034
3056
 
3035
3057
  // src/scan/speed-url.ts
3036
3058
  import * as tls2 from "node:tls";
3059
+ import * as net from "node:net";
3037
3060
  function parseSpeedUrl(raw, fallbackScheme = "https") {
3038
3061
  const value = (raw ?? "").trim();
3039
3062
  if (!value) throw new Error("\u6D4B\u901F\u5730\u5740\u4E3A\u7A7A");
@@ -3104,8 +3127,7 @@ function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
3104
3127
  const socket = parsed.scheme === "https" ? tls2.connect(connectOptions, () => socket.write(request)) : (
3105
3128
  // http 明文:用 net 连接
3106
3129
  (() => {
3107
- const net3 = __require("node:net");
3108
- const s = net3.connect({ host: parsed.host, port: 80 }, () => s.write(request));
3130
+ const s = net.connect({ host: parsed.host, port: 80 }, () => s.write(request));
3109
3131
  return s;
3110
3132
  })()
3111
3133
  );
@@ -3157,17 +3179,17 @@ var init_speed_url = __esm({
3157
3179
  { url: "cf.090227.xyz/__down?bytes=104857600", label: "CM \u63D0\u4F9B" }
3158
3180
  ];
3159
3181
  DEFAULT_SPEED_URL = SPEED_URL_PRESETS[0].url;
3160
- USER_AGENT_FOR_CHECK = "CFPilot-Scanner/1.0 (+https://github.com/xmwengxing/CFPilot)";
3182
+ USER_AGENT_FOR_CHECK = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
3161
3183
  }
3162
3184
  });
3163
3185
 
3164
3186
  // src/scan/scan.ts
3165
- import * as net from "node:net";
3187
+ import * as net2 from "node:net";
3166
3188
  async function tcpPing(ip, port, timeoutMs) {
3167
3189
  return new Promise((resolve2) => {
3168
3190
  const started = Date.now();
3169
3191
  let settled = false;
3170
- const socket = new net.Socket();
3192
+ const socket = new net2.Socket();
3171
3193
  const done = (ok) => {
3172
3194
  if (settled) return;
3173
3195
  settled = true;
@@ -3183,11 +3205,12 @@ async function tcpPing(ip, port, timeoutMs) {
3183
3205
  socket.connect(port, ip);
3184
3206
  });
3185
3207
  }
3186
- async function pool(items, concurrency, worker) {
3208
+ async function pool(items, concurrency, worker, shouldStop) {
3187
3209
  const out = new Array(items.length);
3188
3210
  let cursor = 0;
3189
3211
  const runners = Array.from({ length: Math.max(1, Math.min(concurrency, items.length)) }, async () => {
3190
3212
  for (; ; ) {
3213
+ if (shouldStop?.()) return;
3191
3214
  const index = cursor++;
3192
3215
  if (index >= items.length) return;
3193
3216
  out[index] = await worker(items[index], index);
@@ -3196,12 +3219,17 @@ async function pool(items, concurrency, worker) {
3196
3219
  await Promise.all(runners);
3197
3220
  return out;
3198
3221
  }
3199
- async function withRetry(attempts, fn, isOk = (r) => r.ok === true) {
3222
+ function isTimeoutError(error) {
3223
+ if (!error) return false;
3224
+ return /超时|timeout|timed out|ETIMEDOUT/i.test(error);
3225
+ }
3226
+ async function withRetry(attempts, fn, isOk = (r) => r.ok === true, shouldRetry = () => true) {
3200
3227
  const total = Math.max(1, Math.floor(attempts));
3201
3228
  let last;
3202
3229
  for (let i = 0; i < total; i++) {
3203
3230
  last = await fn();
3204
3231
  if (isOk(last)) return last;
3232
+ if (!shouldRetry(last)) return last;
3205
3233
  }
3206
3234
  return last;
3207
3235
  }
@@ -3211,7 +3239,7 @@ async function runScan(options) {
3211
3239
  const tcpTimeoutMs = options.tcpTimeoutMs ?? 1200;
3212
3240
  const retries = options.retries ?? 2;
3213
3241
  const tlsConcurrency = options.tlsConcurrency ?? 64;
3214
- const tlsTimeoutMs = options.tlsTimeoutMs ?? 4e3;
3242
+ const tlsTimeoutMs = options.tlsTimeoutMs ?? 2e3;
3215
3243
  const maxLatencyMs = options.maxLatencyMs ?? 0;
3216
3244
  const probeLimit = options.probeLimit ?? 120;
3217
3245
  const probeConcurrency = options.probeConcurrency ?? 24;
@@ -3221,6 +3249,9 @@ async function runScan(options) {
3221
3249
  const speedTimeoutMs = options.speedTimeoutMs ?? 12e3;
3222
3250
  const speedBytes = options.speedBytes ?? 5 * 1024 * 1024;
3223
3251
  const top = options.top ?? 15;
3252
+ const countryFilter = normalizeCountryFilter(options.countries ?? []);
3253
+ const hasCountryFilter = countryFilter.length > 0;
3254
+ const effectiveProbeLimit = hasCountryFilter ? Math.max(probeLimit * 4, 500) : probeLimit;
3224
3255
  const candidates = options.candidates;
3225
3256
  const report = options.onProgress ?? (() => {
3226
3257
  });
@@ -3242,30 +3273,37 @@ async function runScan(options) {
3242
3273
  });
3243
3274
  const tcpOk = tcpResults.filter((r) => r.ok);
3244
3275
  const filtered = maxLatencyMs > 0 ? tcpOk.filter((r) => r.latency <= maxLatencyMs) : tcpOk;
3245
- report({ type: "stage", stage: 1, name: "TLS \u63E1\u624B\u7B5B\u9009", total: filtered.length });
3276
+ const tlsCandidateLimit = Math.max(effectiveProbeLimit * 4, 600);
3277
+ const tlsInput = filtered.slice().sort((a, b) => a.latency - b.latency).slice(0, tlsCandidateLimit);
3278
+ report({ type: "stage", stage: 1, name: "TLS \u63E1\u624B\u7B5B\u9009", total: tlsInput.length });
3246
3279
  let tlsDone = 0;
3247
- const tlsResults = await pool(filtered, tlsConcurrency, async (item) => {
3280
+ const tlsResults = await pool(tlsInput, tlsConcurrency, async (item) => {
3248
3281
  const probe = await withRetry(
3249
3282
  retries,
3250
3283
  () => probeTlsHandshake(item.ip, options.port, options.host, tlsTimeoutMs),
3251
- (r) => r.tlsMs > 0
3284
+ (r) => r.tlsMs > 0,
3285
+ // 第 4 个参数:上次失败原因是超时就不要再试
3286
+ (r) => !isTimeoutError(r.error)
3252
3287
  );
3253
3288
  tlsDone++;
3254
- if (tlsDone % 200 === 0 || tlsDone === filtered.length) {
3289
+ if (tlsDone % 200 === 0 || tlsDone === tlsInput.length) {
3255
3290
  report({
3256
3291
  type: "progress",
3257
3292
  stage: 1,
3258
3293
  done: tlsDone,
3259
- total: filtered.length,
3260
- message: `TLS \u63E1\u624B ${tlsDone}/${filtered.length}${probe.tlsMs > 0 ? ` ${probe.tlsMs}ms` : " \u2717"}`
3294
+ total: tlsInput.length,
3295
+ message: `TLS \u63E1\u624B ${tlsDone}/${tlsInput.length}${probe.tlsMs > 0 ? ` ${probe.tlsMs}ms` : " \u2717"}`
3261
3296
  });
3262
3297
  }
3263
3298
  return { ...item, tls: probe };
3264
3299
  });
3265
3300
  const tlsOk = tlsResults.filter((r) => r.tls.tlsMs > 0);
3266
- const stage1 = tlsOk.sort((a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency).slice(0, probeLimit);
3301
+ const stage1 = tlsOk.sort((a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency).slice(0, effectiveProbeLimit);
3267
3302
  const strictProbe = options.verifyPayload !== false;
3268
- const strictProbePath = "/__edge_probe";
3303
+ const explicitProbePath = options.probePath?.trim();
3304
+ const explicitWsPath = options.wsPath?.trim();
3305
+ const strictProbePath = explicitProbePath || // 用户的 wsPath 以 /__edge_probe 开头 → 视为探针端点
3306
+ (explicitWsPath?.startsWith("/__edge_probe") ? explicitWsPath : "") || "/__edge_probe";
3269
3307
  report({
3270
3308
  type: "stage",
3271
3309
  stage: 2,
@@ -3274,29 +3312,46 @@ async function runScan(options) {
3274
3312
  });
3275
3313
  let probeDone = 0;
3276
3314
  let verifiedCount = 0;
3277
- const probeResults = await pool(stage1, probeConcurrency, async (item) => {
3278
- const probeFn = strictProbe ? probeWsPing : probeWs101;
3279
- const probePath = strictProbe ? strictProbePath : options.wsPath ?? "/__edge_probe";
3280
- const result = await withRetry(
3281
- retries,
3282
- () => probeFn(item.ip, options.port, options.host, probeTimeoutMs, probePath)
3283
- );
3284
- probeDone++;
3285
- if (result.pongVerified) verifiedCount++;
3286
- report({
3287
- type: "progress",
3288
- stage: 2,
3289
- done: probeDone,
3290
- total: stage1.length,
3291
- message: strictProbe ? `101+PING \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : result.pongVerified === false ? " \u2717 \u65E0\u54CD\u5E94" : ""}` : `101 \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : ""}`
3292
- });
3293
- return { ...item, probe: result };
3294
- });
3315
+ const earlyExitTarget = hasCountryFilter ? Math.ceil(speedLimit * 1.5) : Infinity;
3316
+ let matchedCount = 0;
3317
+ let stoppedEarly = false;
3318
+ const probeResults = await pool(
3319
+ stage1,
3320
+ probeConcurrency,
3321
+ async (item) => {
3322
+ const probeFn = strictProbe ? probeWsPing : probeWs101;
3323
+ const probePath = strictProbe ? strictProbePath : explicitWsPath || "/__edge_probe";
3324
+ const result = await withRetry(
3325
+ retries,
3326
+ () => probeFn(item.ip, options.port, options.host, probeTimeoutMs, probePath)
3327
+ );
3328
+ probeDone++;
3329
+ if (result.pongVerified) verifiedCount++;
3330
+ if (hasCountryFilter && result.ok && countryFilter.includes(countryOfColo(result.colo || ""))) {
3331
+ matchedCount++;
3332
+ }
3333
+ report({
3334
+ type: "progress",
3335
+ stage: 2,
3336
+ done: probeDone,
3337
+ total: stage1.length,
3338
+ message: strictProbe ? `101+PING \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : result.pongVerified === false ? " \u2717 \u65E0\u54CD\u5E94" : ""}` : `101 \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : ""}`
3339
+ });
3340
+ return { ...item, probe: result };
3341
+ },
3342
+ () => {
3343
+ if (matchedCount >= earlyExitTarget) {
3344
+ stoppedEarly = true;
3345
+ return true;
3346
+ }
3347
+ return false;
3348
+ }
3349
+ );
3295
3350
  const wsOk = strictProbe ? probeResults.filter((r) => r.probe.ok && r.probe.pongVerified === true) : probeResults.filter((r) => r.probe.ok);
3296
- const countryFilter = normalizeCountryFilter(options.countries ?? []);
3297
3351
  let wsFiltered = wsOk;
3298
3352
  let appliedCountries = [];
3299
- if (countryFilter.length > 0 && wsOk.length > 0) {
3353
+ let countryFilterRelaxed = false;
3354
+ if (hasCountryFilter && wsOk.length > 0) {
3300
3355
  const matched = wsOk.filter((r) => countryFilter.includes(countryOfColo(r.probe.colo || "")));
3301
3356
  if (matched.length > 0) {
3302
3357
  wsFiltered = matched;
@@ -3309,12 +3364,13 @@ async function runScan(options) {
3309
3364
  message: `\u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")}\uFF1A\u4FDD\u7559 ${matched.length}/${wsOk.length}\uFF0C\u8FDB\u5165\u6D4B\u901F`
3310
3365
  });
3311
3366
  } else {
3367
+ countryFilterRelaxed = true;
3312
3368
  report({
3313
3369
  type: "progress",
3314
3370
  stage: 2,
3315
3371
  done: wsOk.length,
3316
3372
  total: wsOk.length,
3317
- message: `\u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")} \u540E\u65E0\u5019\u9009\uFF0C\u5DF2\u5FFD\u7565\uFF08\u91C7\u6837\u592A\u5C0F\uFF1F\u8C03\u5230 500~1000 \u518D\u8BD5\uFF09`
3373
+ message: `\u26A0\uFE0F \u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")} \u540E\u65E0\u5019\u9009 \u2014\u2014 \u5DF2\u653E\u5BBD\u4E3A\u5168\u91CF\uFF08${wsOk.length} \u6761\uFF09\u3002\u53EF\u52A0\u5927 --sample \u6216\u6362\u5730\u533A\u91CD\u8BD5`
3318
3374
  });
3319
3375
  }
3320
3376
  }
@@ -3360,7 +3416,7 @@ async function runScan(options) {
3360
3416
  options.host,
3361
3417
  speedBytes,
3362
3418
  speedTimeoutMs,
3363
- options.probePath ?? "/__edge_probe"
3419
+ strictProbePath
3364
3420
  );
3365
3421
  speedDone++;
3366
3422
  report({
@@ -3397,17 +3453,26 @@ async function runScan(options) {
3397
3453
  speedOk: entries.length,
3398
3454
  elapsedMs: Date.now() - started,
3399
3455
  countries: appliedCountries,
3400
- wsFiltered: wsFiltered.length
3456
+ wsFiltered: wsFiltered.length,
3457
+ /** 国家筛选未命中任何候选、已放宽为全量 */
3458
+ countryFilterRelaxed,
3459
+ /** 因已攒够目标国家节点而提前结束阶段二 */
3460
+ stoppedEarly
3401
3461
  }
3402
3462
  };
3403
3463
  report({ type: "done", count: entries.length });
3404
3464
  return summary;
3405
3465
  }
3466
+ function formatHost(ip) {
3467
+ return ip.includes(":") ? `[${ip}]` : ip;
3468
+ }
3406
3469
  function formatCopyable(entries) {
3407
- return entries.map((e) => `${e.ip}:${e.port}#${e.colo}`).join("\n");
3470
+ return entries.map((e) => `${formatHost(e.ip)}:${e.port}#${e.colo}`).join("\n");
3408
3471
  }
3409
3472
  function formatEntries(entries) {
3410
- return entries.map((e) => `${e.ip}:${e.port}#${e.colo}_${e.latency}_${e.speed}`);
3473
+ return entries.map(
3474
+ (e) => `${formatHost(e.ip)}:${e.port}#${e.colo}_${e.latency}_${e.speed}`
3475
+ );
3411
3476
  }
3412
3477
  var init_scan = __esm({
3413
3478
  "src/scan/scan.ts"() {
@@ -3513,16 +3578,14 @@ function cidrWeight(cidr) {
3513
3578
  if (!parsed || parsed.family !== 4) return DEFAULT_CIDR_WEIGHT;
3514
3579
  let bestPrefix = -1;
3515
3580
  let bestWeight = DEFAULT_CIDR_WEIGHT;
3516
- for (const [tableCidr, weight] of Object.entries(IPV4_CIDR_WEIGHTS)) {
3517
- const tableParsed = parseCidr(tableCidr);
3518
- if (!tableParsed || tableParsed.family !== 4) continue;
3519
- if (tableParsed.prefix > parsed.prefix) continue;
3520
- const parsedNorm = parsed.base >> BigInt(32 - tableParsed.prefix);
3521
- const tableNorm = tableParsed.base >> BigInt(32 - tableParsed.prefix);
3581
+ for (const entry of WEIGHT_TABLE) {
3582
+ if (entry.prefix > parsed.prefix) continue;
3583
+ const parsedNorm = parsed.base >> BigInt(32 - entry.prefix);
3584
+ const tableNorm = entry.base >> BigInt(32 - entry.prefix);
3522
3585
  if (parsedNorm !== tableNorm) continue;
3523
- if (tableParsed.prefix > bestPrefix) {
3524
- bestPrefix = tableParsed.prefix;
3525
- bestWeight = weight;
3586
+ if (entry.prefix > bestPrefix) {
3587
+ bestPrefix = entry.prefix;
3588
+ bestWeight = entry.weight;
3526
3589
  }
3527
3590
  }
3528
3591
  return bestWeight;
@@ -3737,12 +3800,20 @@ function expandCidrs(cidrs, options = {}) {
3737
3800
  continue;
3738
3801
  }
3739
3802
  const step = Math.floor(Number(cidr.size) / count);
3740
- const offset = Math.floor(random() * step);
3741
3803
  for (let i = 0; i < count; i++) {
3742
- const offsetValue = BigInt(offset + Math.floor(i * step));
3743
- if (offsetValue >= cidr.size) break;
3744
- const value = cidr.base + offsetValue;
3745
- out.push(family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
3804
+ const jitter = Math.floor(random() * step);
3805
+ let offsetValue = BigInt(i * step + jitter);
3806
+ if (offsetValue >= cidr.size) offsetValue = cidr.size - 1n;
3807
+ let value = cidr.base + offsetValue;
3808
+ if (cidr.family === 4) {
3809
+ const lastOctet = value & 0xffn;
3810
+ if (lastOctet === 0n) value += 1n;
3811
+ else if (lastOctet === 255n) value -= 1n;
3812
+ if (value < cidr.base || value >= cidr.base + cidr.size) {
3813
+ value = cidr.base + offsetValue;
3814
+ }
3815
+ }
3816
+ out.push(cidr.family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
3746
3817
  }
3747
3818
  }
3748
3819
  }
@@ -3775,7 +3846,7 @@ function readIpFile(text) {
3775
3846
  }
3776
3847
  return out;
3777
3848
  }
3778
- var BUILTIN_IPV4_CIDRS, IPV4_CIDR_WEIGHTS, DEFAULT_CIDR_WEIGHT, BUILTIN_IPV6_CIDRS;
3849
+ var BUILTIN_IPV4_CIDRS, IPV4_CIDR_WEIGHTS, DEFAULT_CIDR_WEIGHT, WEIGHT_TABLE, BUILTIN_IPV6_CIDRS;
3779
3850
  var init_ip_ranges = __esm({
3780
3851
  "src/scan/ip-ranges.ts"() {
3781
3852
  "use strict";
@@ -3828,6 +3899,15 @@ var init_ip_ranges = __esm({
3828
3899
  "131.0.72.0/22": 0
3829
3900
  };
3830
3901
  DEFAULT_CIDR_WEIGHT = 0.2;
3902
+ WEIGHT_TABLE = (() => {
3903
+ const out = [];
3904
+ for (const [cidr, weight] of Object.entries(IPV4_CIDR_WEIGHTS)) {
3905
+ const parsed = parseCidr(cidr);
3906
+ if (!parsed || parsed.family !== 4) continue;
3907
+ out.push({ base: parsed.base, prefix: parsed.prefix, weight });
3908
+ }
3909
+ return out;
3910
+ })();
3831
3911
  BUILTIN_IPV6_CIDRS = [
3832
3912
  "2400:cb00::/32",
3833
3913
  "2606:4700::/32",
@@ -3841,11 +3921,11 @@ var init_ip_ranges = __esm({
3841
3921
  });
3842
3922
 
3843
3923
  // src/scan/net-env.ts
3844
- import * as net2 from "node:net";
3924
+ import * as net3 from "node:net";
3845
3925
  import { execFile } from "node:child_process";
3846
3926
  function isPortListening(port, timeoutMs = 400) {
3847
3927
  return new Promise((resolve2) => {
3848
- const socket = new net2.Socket();
3928
+ const socket = new net3.Socket();
3849
3929
  let settled = false;
3850
3930
  const done = (open) => {
3851
3931
  if (settled) return;
@@ -4071,7 +4151,8 @@ __export(server_exports, {
4071
4151
  BRIDGE_VERSION: () => BRIDGE_VERSION,
4072
4152
  DEFAULT_BRIDGE_PORT: () => DEFAULT_BRIDGE_PORT,
4073
4153
  resolveScanCandidates: () => resolveScanCandidates,
4074
- startBridge: () => startBridge
4154
+ startBridge: () => startBridge,
4155
+ validateCallbackUrl: () => validateCallbackUrl
4075
4156
  });
4076
4157
  import { createServer } from "node:http";
4077
4158
  function normalizeSample(value) {
@@ -4105,6 +4186,25 @@ function describePlan(plan) {
4105
4186
  if (plan.source === "request") return `\u4F7F\u7528\u8BF7\u6C42\u643A\u5E26\u7684 ${plan.candidates.length} \u4E2A\u5019\u9009 IP`;
4106
4187
  return `\u5DF2\u81EA\u52A8\u751F\u6210 ${plan.candidates.length} \u4E2A\u5019\u9009 IP`;
4107
4188
  }
4189
+ function pruneJobs() {
4190
+ const now = Date.now();
4191
+ for (const [id, job] of jobs) {
4192
+ if (job.finished && now - job.startedAt > JOB_TTL_MS) {
4193
+ jobs.delete(id);
4194
+ }
4195
+ }
4196
+ const sorted = [...jobs.values()].sort((a, b) => a.startedAt - b.startedAt);
4197
+ while (jobs.size > MAX_JOBS && sorted.length > 0) {
4198
+ const oldest = sorted.shift();
4199
+ jobs.delete(oldest.id);
4200
+ }
4201
+ }
4202
+ function hasRunningJob() {
4203
+ for (const job of jobs.values()) {
4204
+ if (!job.finished) return job;
4205
+ }
4206
+ return null;
4207
+ }
4108
4208
  function corsHeaders() {
4109
4209
  return {
4110
4210
  "Access-Control-Allow-Origin": "*",
@@ -4113,6 +4213,24 @@ function corsHeaders() {
4113
4213
  "Access-Control-Max-Age": "86400"
4114
4214
  };
4115
4215
  }
4216
+ function validateCallbackUrl(raw) {
4217
+ if (!raw || !raw.trim()) return { ok: true };
4218
+ let url;
4219
+ try {
4220
+ url = new URL(raw.trim());
4221
+ } catch {
4222
+ return { ok: false, error: "callback \u4E0D\u662F\u5408\u6CD5 URL" };
4223
+ }
4224
+ if (url.protocol !== "https:") {
4225
+ return { ok: false, error: "callback \u5FC5\u987B\u662F https \u5730\u5740" };
4226
+ }
4227
+ const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
4228
+ const isLocal = host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "0.0.0.0" || host.endsWith(".local") || host.endsWith(".internal") || /^10\./.test(host) || /^192\.168\./.test(host) || /^172\.(1[6-9]|2\d|3[01])\./.test(host) || /^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./.test(host) || /^169\.254\./.test(host);
4229
+ if (isLocal) {
4230
+ return { ok: false, error: "callback \u4E0D\u80FD\u6307\u5411\u672C\u673A\u6216\u5185\u7F51\u5730\u5740" };
4231
+ }
4232
+ return { ok: true };
4233
+ }
4116
4234
  function sendJson(res, status2, data) {
4117
4235
  const body = JSON.stringify(data);
4118
4236
  res.writeHead(status2, {
@@ -4239,6 +4357,21 @@ async function handleRequest(req, res) {
4239
4357
  sendJson(res, 400, { ok: false, error: "\u7F3A\u5C11 host \u53C2\u6570" });
4240
4358
  return;
4241
4359
  }
4360
+ const running = hasRunningJob();
4361
+ if (running) {
4362
+ sendJson(res, 409, {
4363
+ ok: false,
4364
+ error: `\u5DF2\u6709\u626B\u63CF\u4EFB\u52A1\u5728\u8FD0\u884C\uFF08${running.id}\uFF09\uFF0C\u8BF7\u7B49\u5B83\u7ED3\u675F`,
4365
+ jobId: running.id
4366
+ });
4367
+ return;
4368
+ }
4369
+ const callbackCheck = validateCallbackUrl(body.callback);
4370
+ if (!callbackCheck.ok) {
4371
+ sendJson(res, 400, { ok: false, error: callbackCheck.error });
4372
+ return;
4373
+ }
4374
+ pruneJobs();
4242
4375
  const job = {
4243
4376
  id: `job-${Date.now()}-${++jobCounter}`,
4244
4377
  startedAt: Date.now(),
@@ -4273,6 +4406,17 @@ async function handleRequest(req, res) {
4273
4406
  // 国家过滤(可多选):不传 = 全量;无效代码在 normalizeCountryFilter 里被丢弃
4274
4407
  countries: Array.isArray(body.countries) ? body.countries : void 0,
4275
4408
  top: body.top ?? 15,
4409
+ // ⚠️ 必须透传这些参数,否则桥接服务永远用默认值:
4410
+ // wsPath / probePath —— 对接第三方项目(路径不是 /__edge_probe)时,
4411
+ // 阶段二会硬连默认探针路径 → 全军覆没
4412
+ // verifyPayload —— 目标没有探针端点时,内容校验必然失败,
4413
+ // 应自动退回纯 101 校验
4414
+ // speedMode / speedUrl —— 面板可以指定用探针端点还是公开测速地址
4415
+ wsPath: body.wsPath,
4416
+ probePath: body.probePath,
4417
+ verifyPayload: body.verifyPayload,
4418
+ speedMode: body.speedMode,
4419
+ speedUrl: body.speedUrl,
4276
4420
  onProgress: (event) => broadcast(job, event)
4277
4421
  });
4278
4422
  job.result = summary.entries;
@@ -4337,7 +4481,7 @@ async function handleRequest(req, res) {
4337
4481
  }
4338
4482
  sendJson(res, 404, { ok: false, error: "\u63A5\u53E3\u4E0D\u5B58\u5728" });
4339
4483
  }
4340
- var BRIDGE_VERSION, DEFAULT_BRIDGE_PORT, jobs, jobCounter;
4484
+ var BRIDGE_VERSION, DEFAULT_BRIDGE_PORT, jobs, jobCounter, JOB_TTL_MS, MAX_JOBS;
4341
4485
  var init_server = __esm({
4342
4486
  "src/scan/server.ts"() {
4343
4487
  "use strict";
@@ -4348,6 +4492,8 @@ var init_server = __esm({
4348
4492
  DEFAULT_BRIDGE_PORT = 19527;
4349
4493
  jobs = /* @__PURE__ */ new Map();
4350
4494
  jobCounter = 0;
4495
+ JOB_TTL_MS = 10 * 60 * 1e3;
4496
+ MAX_JOBS = 5;
4351
4497
  }
4352
4498
  });
4353
4499
 
@@ -4383,6 +4529,8 @@ scan \u9009\u9879:
4383
4529
  --path <path> \u9636\u6BB5\u4E8C\u6821\u9A8C\u7684 WebSocket \u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /__edge_probe
4384
4530
  \uFF08\u5BF9\u63A5\u5176\u5B83\u9879\u76EE\u65F6\u586B\u5B83\u81EA\u5DF1\u7684 WS \u8DEF\u5F84\uFF0C\u4F8B\u5982 /vless \u6216 /<uuid>\uFF09
4385
4531
  --probe-path <path> probe \u6A21\u5F0F\u7684\u6D4B\u901F\u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /__edge_probe
4532
+ \u663E\u5F0F\u6307\u5B9A\u540E\uFF0C\u9636\u6BB5\u4E8C\u7684\u5185\u5BB9\u6821\u9A8C\u4E5F\u4F1A\u8D70\u8FD9\u4E2A\u8DEF\u5F84
4533
+ \uFF08\u5BF9\u63A5\u7B2C\u4E09\u65B9\u9879\u76EE\u65F6\u7528\uFF1B\u63A2\u9488\u7AEF\u70B9\u4E0D\u662F /__edge_probe \u65F6\u5FC5\u586B\uFF09
4386
4534
  --speed-mode <mode> \u6D4B\u901F\u65B9\u5F0F\uFF1Aauto\uFF08\u9ED8\u8BA4\uFF09/ probe / url
4387
4535
  auto = \u76EE\u6807\u6709\u63A2\u9488\u7AEF\u70B9\u5C31\u7528\u5B83\uFF0C\u5426\u5219\u81EA\u52A8\u6539\u7528\u516C\u5F00\u6D4B\u901F\u5730\u5740
4388
4536
  probe = \u53EA\u7528\u76EE\u6807\u9879\u76EE\u7684\u63A2\u9488\u7AEF\u70B9\uFF08\u6700\u5FE0\u5B9E\uFF0C\u8981\u6C42\u5BF9\u65B9\u6709\u8BE5\u7AEF\u70B9\uFF09
@@ -4396,6 +4544,7 @@ scan \u9009\u9879:
4396
4544
  \u771F\u673A\u5076\u53D1\u5931\u8D25\u7387 3~5%\uFF0C\u91CD\u8BD5\u53D6\u7B2C\u4E00\u6B21\u6210\u529F\u7684\u7ED3\u679C
4397
4545
  --no-verify \u9636\u6BB5\u4E8C\u53EA\u505A 101 \u63E1\u624B\uFF0C\u8DF3\u8FC7\u54CD\u5E94\u4F53\u6821\u9A8C
4398
4546
  \uFF08\u9ED8\u8BA4\u6821\u9A8C\uFF1A\u53D1 PING \u5E76\u9A8C\u8BC1\u6570\u636E\u9762\u56DE {"pong":true}\uFF09
4547
+ \u76EE\u6807\u6CA1\u6709\u63A2\u9488\u7AEF\u70B9\u65F6\u4F1A\u81EA\u52A8\u964D\u7EA7\u4E3A\u7EAF 101 \u6821\u9A8C
4399
4548
  --no-speed \u8DF3\u8FC7\u6D4B\u901F\uFF0C\u53EA\u6309\u5EF6\u8FDF\u6392\u5E8F
4400
4549
  --top <n> \u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 15
4401
4550
  --concurrency <n> \u9636\u6BB5\u4E00 TCP \u5E76\u53D1\uFF0C\u9ED8\u8BA4 300
@@ -4405,13 +4554,18 @@ scan \u9009\u9879:
4405
4554
  \u5EFA\u8BAE 6556 \u8D77\uFF1A\u9636\u6BB5\u4E00\u6309 TLS \u63E1\u624B\u8017\u65F6\u7B5B\u9009\uFF0C\u800C\u63E1\u624B\u5FEB\u6162
4406
4555
  \u4E0E TCP \u5EF6\u8FDF\u51E0\u4E4E\u65E0\u5173\uFF08\u5B9E\u6D4B TCP 9ms \u7684 IP \u53EF\u80FD\u8981 3.5 \u79D2\uFF09\uFF0C
4407
4556
  \u91C7\u6837\u5C0F\u4E86\u6839\u672C\u78B0\u4E0D\u5230\u63E1\u624B\u5FEB\u7684 IP
4408
- --countries <a,b> \u56FD\u5BB6 / \u5730\u533A\u8FC7\u6EE4\uFF08\u53EF\u591A\u9009\uFF0C\u9017\u53F7\u5206\u9694\uFF0C\u5982 HK,JP,SG\uFF09
4409
- \u4E0D\u9009 = \u5168\u91CF\u3002\u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\uFF1B\u7B5B\u5B8C\u4E3A\u7A7A\u4F1A\u81EA\u52A8\u5FFD\u7565
4557
+ --countries <a,b> \u56FD\u5BB6 / \u5730\u533A\u8FC7\u6EE4\uFF08\u53EF\u591A\u9009\uFF0C\u9017\u53F7\u5206\u9694\uFF0C\u5982 US,JP,SG\uFF09
4558
+ \u4E0D\u9009 = \u5168\u91CF\u3002\u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\u3002
4559
+ \u5E26\u6B64\u53C2\u6570\u4F1A\u81EA\u52A8\u6269\u5927 101 \u6821\u9A8C\u7684\u5019\u9009\u6C60\uFF08120 \u2192 \u6700\u591A 500\uFF09\uFF0C
4560
+ \u5426\u5219\u76EE\u6807\u5730\u533A\u53EF\u80FD\u56E0\u5EF6\u8FDF\u6392\u5E8F\u88AB\u63D0\u524D\u622A\u65AD\uFF1B
4561
+ \u7B5B\u4E0D\u5230\u65F6\u4F1A\u660E\u786E\u63D0\u793A\u300C\u5DF2\u653E\u5BBD\u4E3A\u5168\u91CF\u300D\u800C\u4E0D\u662F\u9759\u9ED8\u5FFD\u7565
4410
4562
  --cidr <a,b> \u81EA\u5B9A\u4E49\u7F51\u6BB5\uFF08\u53EF\u91CD\u590D\uFF0C\u7528\u9017\u53F7\u5206\u9694\uFF09
4411
4563
  --ip-file <path> \u4F7F\u7528\u672C\u5730 IP \u5217\u8868\u6587\u4EF6
4412
4564
  --max-latency <ms> \u9636\u6BB5\u4E00 TCP \u5EF6\u8FDF\u4E0A\u9650\uFF0C\u9ED8\u8BA4 0\uFF08\u4E0D\u9650\uFF09
4413
- --tls-timeout <ms> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u8D85\u65F6\uFF0C\u9ED8\u8BA4 4000
4565
+ --tls-timeout <ms> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u8D85\u65F6\uFF0C\u9ED8\u8BA4 2000
4566
+ \u8D85\u65F6\u4E0D\u518D\u91CD\u8BD5\uFF08\u8BE5 IP \u5728\u5F53\u524D\u7F51\u7EDC\u4E0B\u5C31\u662F\u4E0D\u53EF\u7528\uFF09
4414
4567
  --probe-limit <n> \u8FDB\u5165 101 \u6821\u9A8C\u7684\u5019\u9009\u6570\uFF0C\u9ED8\u8BA4 120
4568
+ \u5E26 --countries \u65F6\u81EA\u52A8\u653E\u5927\u5230 max(120*4, 500)
4415
4569
  --speed-limit <n> \u8FDB\u5165\u6D4B\u901F\u7684\u5019\u9009\u6570\uFF0C\u9ED8\u8BA4 30
4416
4570
  --speed-bytes <n> \u6D4B\u901F\u5B57\u8282\u6570\uFF0C\u9ED8\u8BA4 5242880
4417
4571
  --timeout <ms> \u9636\u6BB5\u4E00\u8D85\u65F6\uFF0C\u9ED8\u8BA4 1200
@@ -4511,7 +4665,7 @@ function printTable(entries) {
4511
4665
  process.stdout.write("\u2500".repeat(66) + "\n");
4512
4666
  entries.forEach((entry, index) => {
4513
4667
  const rank = String(index + 1).padStart(2, " ");
4514
- const address = `${entry.ip}:${entry.port}`.padEnd(24, " ");
4668
+ const address = `${formatHost(entry.ip)}:${entry.port}`.padEnd(24, " ");
4515
4669
  const colo = (entry.colo || "UNK").padEnd(6, " ");
4516
4670
  const tls3 = String(entry.tlsMs).padStart(7, " ");
4517
4671
  const latency = String(entry.latency).padStart(7, " ");
@@ -4572,10 +4726,10 @@ async function runScanCommand(args) {
4572
4726
  const top = flagNumber(args, "top", 15);
4573
4727
  let token = flagString(args, "token");
4574
4728
  const noCallback = flagBool(args, "no-callback");
4729
+ const askCallback = flagBool(args, "ask-callback");
4575
4730
  const wsPath = normalizeWsPath(flagString(args, "path"), "/__edge_probe");
4576
4731
  const probePath = normalizeWsPath(flagString(args, "probe-path"), "/__edge_probe");
4577
4732
  const noSpeed = flagBool(args, "no-speed");
4578
- const verifyPayload = !flagBool(args, "no-verify");
4579
4733
  const countries = normalizeCountryFilter(flagList(args, "countries"));
4580
4734
  const panelHost = flagString(args, "panel");
4581
4735
  const panelPassword = flagString(args, "panel-password");
@@ -4645,6 +4799,22 @@ ${NAME} v${VERSION}
4645
4799
  let skipSpeed = noSpeed;
4646
4800
  let speedMode = "probe";
4647
4801
  let speedUrl = flagString(args, "speed-url", DEFAULT_SPEED_URL);
4802
+ let verifyPayload = !flagBool(args, "no-verify");
4803
+ let hasProbeEndpoint = null;
4804
+ const detectProbeEndpoint = async () => {
4805
+ try {
4806
+ const probe = await fetch(`https://${host}${probePath}?bytes=1024`, {
4807
+ method: "GET",
4808
+ signal: AbortSignal.timeout(8e3)
4809
+ });
4810
+ return Boolean(probe.headers.get("x-probe-bytes"));
4811
+ } catch {
4812
+ return null;
4813
+ }
4814
+ };
4815
+ if (verifyPayload) {
4816
+ hasProbeEndpoint = await detectProbeEndpoint();
4817
+ }
4648
4818
  if (!skipSpeed) {
4649
4819
  const forcedMode = flagString(args, "speed-mode");
4650
4820
  if (forcedMode === "url") {
@@ -4654,16 +4824,10 @@ ${NAME} v${VERSION}
4654
4824
  } else if (forcedMode === "probe") {
4655
4825
  speedMode = "probe";
4656
4826
  } else {
4657
- let hasProbe = false;
4658
- try {
4659
- const probe = await fetch(`https://${host}${probePath}?bytes=1024`, {
4660
- method: "GET",
4661
- signal: AbortSignal.timeout(8e3)
4662
- });
4663
- hasProbe = Boolean(probe.headers.get("x-probe-bytes"));
4664
- } catch {
4665
- hasProbe = false;
4827
+ if (hasProbeEndpoint === null) {
4828
+ hasProbeEndpoint = await detectProbeEndpoint();
4666
4829
  }
4830
+ const hasProbe = hasProbeEndpoint;
4667
4831
  if (hasProbe) {
4668
4832
  speedMode = "probe";
4669
4833
  if (!quiet) process.stdout.write("\u6D4B\u901F\u65B9\u5F0F\uFF1A\u9879\u76EE\u63A2\u9488\u7AEF\u70B9\uFF08\u6700\u5FE0\u5B9E\uFF09\n");
@@ -4683,6 +4847,12 @@ ${NAME} v${VERSION}
4683
4847
  }
4684
4848
  }
4685
4849
  }
4850
+ if (hasProbeEndpoint === false && verifyPayload) {
4851
+ verifyPayload = false;
4852
+ if (!quiet) {
4853
+ process.stdout.write("\n\u63D0\u793A\uFF1A\u76EE\u6807\u65E0\u63A2\u9488\u7AEF\u70B9\uFF0C\u5DF2\u81EA\u52A8\u5173\u95ED\u54CD\u5E94\u4F53\u6821\u9A8C\uFF08\u9000\u56DE\u7EAF 101 \u6821\u9A8C\uFF09\n");
4854
+ }
4855
+ }
4686
4856
  const summary = await runScan({
4687
4857
  host,
4688
4858
  port,
@@ -4696,7 +4866,7 @@ ${NAME} v${VERSION}
4696
4866
  retries: flagNumber(args, "retries", 2),
4697
4867
  tcpTimeoutMs: flagNumber(args, "timeout", 1200),
4698
4868
  tlsConcurrency: flagNumber(args, "tls-concurrency", 64),
4699
- tlsTimeoutMs: flagNumber(args, "tls-timeout", 4e3),
4869
+ tlsTimeoutMs: flagNumber(args, "tls-timeout", 2e3),
4700
4870
  maxLatencyMs: flagNumber(args, "max-latency", 0),
4701
4871
  probeLimit: flagNumber(args, "probe-limit", 120),
4702
4872
  probeTimeoutMs: flagNumber(args, "probe-timeout", 3e3),
@@ -4731,10 +4901,72 @@ ${NAME} v${VERSION}
4731
4901
  `);
4732
4902
  process.exitCode = 1;
4733
4903
  }
4734
- } else if (!quiet) {
4904
+ } else if (askCallback && !quiet && summary.entries.length > 0) {
4905
+ await promptCallback(summary.entries, host, panelHost, panelPassword);
4906
+ } else if (!quiet && !asJson) {
4735
4907
  process.stdout.write("\n\uFF08\u672A\u63D0\u4F9B --token\uFF0C\u8DF3\u8FC7\u56DE\u586B\uFF09\n");
4736
4908
  }
4737
4909
  }
4910
+ async function promptCallback(entries, dataHost, panelHost, panelPassword) {
4911
+ const { createInterface: createInterface2 } = await import("node:readline/promises");
4912
+ const { stdin: stdin2, stdout: stdout2 } = await import("node:process");
4913
+ process.stdout.write("\n" + "\u2500".repeat(50) + "\n");
4914
+ if (!panelHost) {
4915
+ process.stdout.write("\u672A\u914D\u7F6E\u63A7\u5236\u9762\u57DF\u540D\uFF0C\u65E0\u6CD5\u56DE\u586B\u3002\n");
4916
+ process.stdout.write("\u2192 \u53EF\u624B\u52A8\u590D\u5236\u4E0A\u9762\u7684 IP \u5217\u8868\uFF0C\u7C98\u8D34\u5230\u9762\u677F\u300C\u624B\u52A8\u4F18\u9009 IP\u300D\n");
4917
+ return;
4918
+ }
4919
+ const rl = createInterface2({ input: stdin2, output: stdout2 });
4920
+ let answer = "";
4921
+ try {
4922
+ answer = (await rl.question(`\u662F\u5426\u56DE\u586B\u8FD9 ${entries.length} \u6761\u5230\u9762\u677F\uFF1F(y/N): `)).trim().toLowerCase();
4923
+ } finally {
4924
+ rl.close();
4925
+ }
4926
+ if (answer !== "y" && answer !== "yes") {
4927
+ process.stdout.write("\n\u5DF2\u8DF3\u8FC7\u56DE\u586B\u3002\n");
4928
+ process.stdout.write("\u2192 \u4E0A\u9762\u7684 IP \u5217\u8868\u53EF\u76F4\u63A5\u590D\u5236\uFF0C\u7C98\u8D34\u5230\u9762\u677F\u300C\u624B\u52A8\u4F18\u9009 IP\u300D\u6846\n");
4929
+ return;
4930
+ }
4931
+ let password = panelPassword;
4932
+ if (!password) {
4933
+ const rl2 = createInterface2({ input: stdin2, output: stdout2 });
4934
+ try {
4935
+ password = (await rl2.question("\u9762\u677F\u5BC6\u7801\uFF08\u7528\u4E8E\u7533\u8BF7\u4E34\u65F6\u4EE4\u724C\uFF09: ")).trim();
4936
+ } finally {
4937
+ rl2.close();
4938
+ }
4939
+ }
4940
+ if (!password) {
4941
+ process.stdout.write("\n\u672A\u63D0\u4F9B\u9762\u677F\u5BC6\u7801\uFF0C\u5DF2\u8DF3\u8FC7\u56DE\u586B\u3002\n");
4942
+ process.stdout.write("\u2192 \u53EF\u624B\u52A8\u590D\u5236\u4E0A\u9762\u7684 IP \u5217\u8868\u7C98\u8D34\u5230\u9762\u677F\n");
4943
+ return;
4944
+ }
4945
+ process.stdout.write("\n\u6B63\u5728\u7533\u8BF7\u4E34\u65F6\u4EE4\u724C\u2026\n");
4946
+ const tk = await fetchScannerToken(panelHost, password);
4947
+ if (!tk.ok || !tk.token) {
4948
+ process.stdout.write(`\u2717 \u83B7\u53D6\u4EE4\u724C\u5931\u8D25\uFF1A${tk.error ?? "\u672A\u77E5\u9519\u8BEF"}
4949
+ `);
4950
+ process.stdout.write("\u2192 \u53EF\u624B\u52A8\u590D\u5236\u4E0A\u9762\u7684 IP \u5217\u8868\u7C98\u8D34\u5230\u9762\u677F\n");
4951
+ return;
4952
+ }
4953
+ process.stdout.write("\u2713 \u5DF2\u83B7\u53D6\u4E34\u65F6\u4EE4\u724C\uFF0810 \u5206\u949F\u6709\u6548\uFF09\n");
4954
+ const url = `https://${panelHost.replace(/^https?:\/\//, "").replace(/\/$/, "")}/api/v1/preferred-ips`;
4955
+ process.stdout.write(`\u6B63\u5728\u56DE\u586B\u5230 ${url} \u2026
4956
+ `);
4957
+ const result = await postResults(url, tk.token, formatEntries(entries));
4958
+ if (result.ok) {
4959
+ process.stdout.write(`
4960
+ \u2713 \u5DF2\u56DE\u586B ${entries.length} \u6761\u5230\u9762\u677F\u300C\u624B\u52A8\u4F18\u9009 IP\u300D
4961
+ `);
4962
+ process.stdout.write("\u2192 \u6253\u5F00\u9762\u677F\u300C\u8282\u70B9\u6765\u6E90 \u2192 \u624B\u52A8\u4F18\u9009 IP\u300D\u70B9\u300C\u67E5\u770B\u300D\u5373\u53EF\u770B\u5230\n");
4963
+ } else {
4964
+ process.stdout.write(`
4965
+ \u2717 \u56DE\u586B\u5931\u8D25\uFF1A${result.error}
4966
+ `);
4967
+ process.stdout.write("\u2192 \u53EF\u624B\u52A8\u590D\u5236\u4E0A\u9762\u7684 IP \u5217\u8868\u7C98\u8D34\u5230\u9762\u677F\n");
4968
+ }
4969
+ }
4738
4970
  var init_command2 = __esm({
4739
4971
  "src/scan/command.ts"() {
4740
4972
  "use strict";
@@ -4854,7 +5086,8 @@ async function menuScan() {
4854
5086
  const flags = {
4855
5087
  host: cfg.dataHost ?? "",
4856
5088
  sample: String(sample),
4857
- "no-callback": true
5089
+ "ask-callback": true,
5090
+ panel: cfg.panelHost ?? ""
4858
5091
  };
4859
5092
  if (skipSpeed) flags["no-speed"] = true;
4860
5093
  if (countries.length > 0) flags["countries"] = countries.join(",");
@@ -5225,7 +5458,6 @@ async function runMenu() {
5225
5458
  { label: "\u66F4\u65B0\u73B0\u6709\u5B9E\u4F8B", value: "deploy-update", hint: "\u6CBF\u7528\u51ED\u636E\uFF0C\u53EA\u66F4\u65B0\u5185\u6838" },
5226
5459
  { label: "\u67E5\u770B\u5B9E\u4F8B\u72B6\u6001", value: "status", hint: "\u8BFB\u53D6\u7EBF\u4E0A\u90E8\u7F72\u4FE1\u606F" },
5227
5460
  { label: "\u672C\u5730\u4F18\u9009\uFF08\u771F\u8FDE\u63A5\u6D4B\u901F\uFF09", value: "scan", hint: "\u626B\u63CF\u53EF\u7528 IP" },
5228
- { label: "\u56DE\u586B\u4F18\u9009\u7ED3\u679C\u5230\u9762\u677F", value: "scan-push", hint: "\u5199\u5165\u9762\u677F\u7684\u300C\u624B\u52A8\u4F18\u9009 IP\u300D" },
5229
5461
  { label: "\u4FEE\u6539\u9762\u677F\u5BC6\u7801", value: "change-password" },
5230
5462
  { label: "\u68C0\u67E5 Token \u6743\u9650", value: "token-check" },
5231
5463
  { label: "\u914D\u7F6E\uFF08Token / \u8D26\u53F7 / KV\uFF09", value: "config" },
@@ -5261,11 +5493,6 @@ async function runMenu() {
5261
5493
  await menuScan2();
5262
5494
  break;
5263
5495
  }
5264
- case "scan-push": {
5265
- const { menuScanPush: menuScanPush2 } = await Promise.resolve().then(() => (init_scan2(), scan_exports));
5266
- await menuScanPush2();
5267
- break;
5268
- }
5269
5496
  case "change-password": {
5270
5497
  const { menuChangePassword: menuChangePassword2 } = await Promise.resolve().then(() => (init_deploy(), deploy_exports));
5271
5498
  await menuChangePassword2();