cfpilot 0.16.5 → 0.20.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/assets/control.js +12 -13
- package/assets/dataplane.js +5 -5
- package/assets/worker.js +18 -22
- package/dist/cli.js +394 -67
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -87,7 +87,7 @@ var VERSION, NAME;
|
|
|
87
87
|
var init_version = __esm({
|
|
88
88
|
"src/shared/version.ts"() {
|
|
89
89
|
"use strict";
|
|
90
|
-
VERSION = "0.
|
|
90
|
+
VERSION = "0.20.0";
|
|
91
91
|
NAME = "cfpilot";
|
|
92
92
|
}
|
|
93
93
|
});
|
|
@@ -4064,7 +4064,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
|
4064
4064
|
});
|
|
4065
4065
|
});
|
|
4066
4066
|
}
|
|
4067
|
-
function probeTlsHandshake(ip, port, host, timeoutMs = 4e3) {
|
|
4067
|
+
function probeTlsHandshake(ip, port, host, timeoutMs = 4e3, alpn = "http/1.1") {
|
|
4068
4068
|
return new Promise((resolve4) => {
|
|
4069
4069
|
const started = Date.now();
|
|
4070
4070
|
let settled = false;
|
|
@@ -4078,21 +4078,22 @@ function probeTlsHandshake(ip, port, host, timeoutMs = 4e3) {
|
|
|
4078
4078
|
}
|
|
4079
4079
|
resolve4({ ip, tlsMs: result.tlsMs ?? Date.now() - started, ...result });
|
|
4080
4080
|
};
|
|
4081
|
+
const expect = alpn === "h2" ? "h2" : "http/1.1";
|
|
4081
4082
|
const socket = tls.connect(
|
|
4082
4083
|
{
|
|
4083
4084
|
host: ip,
|
|
4084
4085
|
port,
|
|
4085
4086
|
servername: host,
|
|
4086
4087
|
rejectUnauthorized: false,
|
|
4087
|
-
ALPNProtocols: [
|
|
4088
|
+
ALPNProtocols: [expect]
|
|
4088
4089
|
},
|
|
4089
4090
|
() => {
|
|
4090
|
-
const
|
|
4091
|
-
if (
|
|
4092
|
-
finish({ error: `ALPN=${
|
|
4091
|
+
const got = socket.alpnProtocol;
|
|
4092
|
+
if (got && got !== expect) {
|
|
4093
|
+
finish({ error: `ALPN=${got}` });
|
|
4093
4094
|
return;
|
|
4094
4095
|
}
|
|
4095
|
-
finish({ tlsMs: Date.now() - started, alpn:
|
|
4096
|
+
finish({ tlsMs: Date.now() - started, alpn: got || void 0 });
|
|
4096
4097
|
}
|
|
4097
4098
|
);
|
|
4098
4099
|
const timer = setTimeout(() => finish({ error: "TLS \u63E1\u624B\u8D85\u65F6" }), timeoutMs);
|
|
@@ -4359,6 +4360,225 @@ function verifyTunnel(options) {
|
|
|
4359
4360
|
});
|
|
4360
4361
|
});
|
|
4361
4362
|
}
|
|
4363
|
+
function randomXhttpSession() {
|
|
4364
|
+
return "sess-" + crypto.randomBytes(8).toString("hex");
|
|
4365
|
+
}
|
|
4366
|
+
function h2Authority(ip, port) {
|
|
4367
|
+
return `https://${ip.includes(":") ? `[${ip}]` : ip}:${port}`;
|
|
4368
|
+
}
|
|
4369
|
+
function extractColoFromHeaders(headers) {
|
|
4370
|
+
const ray = String(headers["cf-ray"] ?? "");
|
|
4371
|
+
const m = /([A-Z]{3})$/.exec(ray.trim().toUpperCase());
|
|
4372
|
+
return m ? m[1] : "";
|
|
4373
|
+
}
|
|
4374
|
+
function probeXhttpEndpoint(ip, port, host, xhttpPath, timeoutMs = 3e3) {
|
|
4375
|
+
return new Promise((resolve4) => {
|
|
4376
|
+
void (async () => {
|
|
4377
|
+
const started = Date.now();
|
|
4378
|
+
const session = randomXhttpSession();
|
|
4379
|
+
const base = xhttpPath.replace(/\/+$/, "") || "/xhttp";
|
|
4380
|
+
let settled = false;
|
|
4381
|
+
let client = null;
|
|
4382
|
+
const finish = (r) => {
|
|
4383
|
+
if (settled) return;
|
|
4384
|
+
settled = true;
|
|
4385
|
+
clearTimeout(timer);
|
|
4386
|
+
try {
|
|
4387
|
+
client?.close();
|
|
4388
|
+
} catch {
|
|
4389
|
+
}
|
|
4390
|
+
try {
|
|
4391
|
+
client?.destroy();
|
|
4392
|
+
} catch {
|
|
4393
|
+
}
|
|
4394
|
+
resolve4({ ...r, latencyMs: Date.now() - started });
|
|
4395
|
+
};
|
|
4396
|
+
const timer = setTimeout(() => {
|
|
4397
|
+
finish({ ok: false, colo: "", status: 0, error: "XHTTP \u63E1\u624B\u8D85\u65F6" });
|
|
4398
|
+
}, timeoutMs);
|
|
4399
|
+
try {
|
|
4400
|
+
const http2 = await import("node:http2");
|
|
4401
|
+
client = http2.connect(h2Authority(ip, port), {
|
|
4402
|
+
servername: host,
|
|
4403
|
+
ALPNProtocols: ["h2"],
|
|
4404
|
+
rejectUnauthorized: false
|
|
4405
|
+
});
|
|
4406
|
+
client.on("error", (...args) => {
|
|
4407
|
+
const err = args[0];
|
|
4408
|
+
finish({ ok: false, colo: "", status: 0, error: err.message });
|
|
4409
|
+
});
|
|
4410
|
+
const req = client.request({
|
|
4411
|
+
":method": "POST",
|
|
4412
|
+
":path": `${base}/${session}/0`,
|
|
4413
|
+
":authority": `${host}:${port}`,
|
|
4414
|
+
"content-type": "text/plain",
|
|
4415
|
+
host,
|
|
4416
|
+
referer: `https://${host}${base}/?x_padding=${"X".repeat(200)}`
|
|
4417
|
+
});
|
|
4418
|
+
req.on("response", (...args) => {
|
|
4419
|
+
const headers = args[0];
|
|
4420
|
+
const status2 = Number(headers[":status"] ?? 0);
|
|
4421
|
+
const colo = extractColoFromHeaders(headers);
|
|
4422
|
+
if (status2 === 400) {
|
|
4423
|
+
finish({ ok: true, colo, status: status2 });
|
|
4424
|
+
return;
|
|
4425
|
+
}
|
|
4426
|
+
req.destroy();
|
|
4427
|
+
finish({
|
|
4428
|
+
ok: false,
|
|
4429
|
+
colo,
|
|
4430
|
+
status: status2,
|
|
4431
|
+
error: status2 === 403 ? "HTTP 403\uFF08\u8FB9\u7F18\u62E6\u622A\uFF09" : `HTTP ${status2}`
|
|
4432
|
+
});
|
|
4433
|
+
});
|
|
4434
|
+
req.on("error", (...args) => {
|
|
4435
|
+
const err = args[0];
|
|
4436
|
+
finish({ ok: false, colo: "", status: 0, error: err.message });
|
|
4437
|
+
});
|
|
4438
|
+
req.end(Buffer.from("probe"));
|
|
4439
|
+
} catch (err) {
|
|
4440
|
+
finish({
|
|
4441
|
+
ok: false,
|
|
4442
|
+
colo: "",
|
|
4443
|
+
status: 0,
|
|
4444
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4445
|
+
});
|
|
4446
|
+
}
|
|
4447
|
+
})();
|
|
4448
|
+
});
|
|
4449
|
+
}
|
|
4450
|
+
function verifyXhttpTunnel(options) {
|
|
4451
|
+
const { ip, port, host } = options;
|
|
4452
|
+
const base = (options.xhttpPath ?? "/xhttp").replace(/\/+$/, "") || "/xhttp";
|
|
4453
|
+
const targetHost = options.targetHost ?? "baidu.com";
|
|
4454
|
+
const targetPort = options.targetPort ?? 80;
|
|
4455
|
+
const timeoutMs = options.timeoutMs ?? 8e3;
|
|
4456
|
+
const payload = options.uuid ? buildVlessTunnelPayload(options.uuid, targetHost, targetPort, tunnelTargetRequest(targetHost)) : null;
|
|
4457
|
+
if (!payload) {
|
|
4458
|
+
return Promise.resolve({ ok: false, stage: "protocol", latencyMs: 0, error: "\u7F3A\u5C11 uuid" });
|
|
4459
|
+
}
|
|
4460
|
+
return new Promise((resolve4) => {
|
|
4461
|
+
void (async () => {
|
|
4462
|
+
const started = Date.now();
|
|
4463
|
+
const session = randomXhttpSession();
|
|
4464
|
+
let settled = false;
|
|
4465
|
+
let stage = "handshake";
|
|
4466
|
+
let client = null;
|
|
4467
|
+
const finish = (r) => {
|
|
4468
|
+
if (settled) return;
|
|
4469
|
+
settled = true;
|
|
4470
|
+
clearTimeout(timer);
|
|
4471
|
+
try {
|
|
4472
|
+
client?.close();
|
|
4473
|
+
} catch {
|
|
4474
|
+
}
|
|
4475
|
+
try {
|
|
4476
|
+
client?.destroy();
|
|
4477
|
+
} catch {
|
|
4478
|
+
}
|
|
4479
|
+
resolve4({ ...r, latencyMs: Date.now() - started });
|
|
4480
|
+
};
|
|
4481
|
+
const timer = setTimeout(() => {
|
|
4482
|
+
finish({
|
|
4483
|
+
ok: false,
|
|
4484
|
+
stage,
|
|
4485
|
+
error: stage === "data" ? "\u4E0B\u884C\u65E0\u56DE\u5305" : stage === "protocol" ? "VLESS \u54CD\u5E94\u5934\u8D85\u65F6" : "XHTTP \u63E1\u624B\u8D85\u65F6"
|
|
4486
|
+
});
|
|
4487
|
+
}, timeoutMs);
|
|
4488
|
+
try {
|
|
4489
|
+
const http2 = await import("node:http2");
|
|
4490
|
+
client = http2.connect(h2Authority(ip, port), {
|
|
4491
|
+
servername: host,
|
|
4492
|
+
ALPNProtocols: ["h2"],
|
|
4493
|
+
rejectUnauthorized: false
|
|
4494
|
+
});
|
|
4495
|
+
client.on("error", (...args) => {
|
|
4496
|
+
const err = args[0];
|
|
4497
|
+
finish({ ok: false, stage, error: err.message });
|
|
4498
|
+
});
|
|
4499
|
+
const upHeaders = {
|
|
4500
|
+
":method": "POST",
|
|
4501
|
+
":path": `${base}/${session}/0`,
|
|
4502
|
+
":authority": `${host}:${port}`,
|
|
4503
|
+
"content-type": "text/plain",
|
|
4504
|
+
host,
|
|
4505
|
+
referer: `https://${host}${base}/?x_padding=${"X".repeat(200)}`
|
|
4506
|
+
};
|
|
4507
|
+
const up = client.request(upHeaders);
|
|
4508
|
+
up.on("response", (...args) => {
|
|
4509
|
+
const headers = args[0];
|
|
4510
|
+
const status2 = Number(headers[":status"] ?? 0);
|
|
4511
|
+
const colo = extractColoFromHeaders(headers);
|
|
4512
|
+
if (status2 !== 200) {
|
|
4513
|
+
finish({ ok: false, stage: "handshake", colo, error: `HTTP ${status2}` });
|
|
4514
|
+
}
|
|
4515
|
+
});
|
|
4516
|
+
up.on("error", (...args) => {
|
|
4517
|
+
const err = args[0];
|
|
4518
|
+
finish({ ok: false, stage: "handshake", error: err.message });
|
|
4519
|
+
});
|
|
4520
|
+
up.end(payload);
|
|
4521
|
+
const t = setInterval(() => {
|
|
4522
|
+
if (up.destroyed || up.closed) clearInterval(t);
|
|
4523
|
+
}, 200);
|
|
4524
|
+
setTimeout(() => {
|
|
4525
|
+
if (settled) return;
|
|
4526
|
+
stage = "protocol";
|
|
4527
|
+
const down = client.request({
|
|
4528
|
+
":method": "GET",
|
|
4529
|
+
":path": `${base}/${session}`,
|
|
4530
|
+
":authority": `${host}:${port}`,
|
|
4531
|
+
host,
|
|
4532
|
+
referer: `https://${host}${base}/?x_padding=${"X".repeat(200)}`
|
|
4533
|
+
});
|
|
4534
|
+
let buf = Buffer.alloc(0);
|
|
4535
|
+
let headDone = false;
|
|
4536
|
+
down.on("response", (...args) => {
|
|
4537
|
+
const headers = args[0];
|
|
4538
|
+
const status2 = Number(headers[":status"] ?? 0);
|
|
4539
|
+
const colo = extractColoFromHeaders(headers);
|
|
4540
|
+
if (status2 !== 200) {
|
|
4541
|
+
finish({ ok: false, stage: "protocol", colo, error: `HTTP ${status2}` });
|
|
4542
|
+
return;
|
|
4543
|
+
}
|
|
4544
|
+
stage = "data";
|
|
4545
|
+
});
|
|
4546
|
+
down.on("error", (...args) => {
|
|
4547
|
+
const err = args[0];
|
|
4548
|
+
finish({ ok: false, stage, error: err.message });
|
|
4549
|
+
});
|
|
4550
|
+
down.on("data", (...args) => {
|
|
4551
|
+
const chunk = args[0];
|
|
4552
|
+
buf = Buffer.concat([buf, chunk]);
|
|
4553
|
+
if (!headDone) {
|
|
4554
|
+
if (buf.length < 2) return;
|
|
4555
|
+
if (buf[0] !== 0 || buf[1] !== 0) {
|
|
4556
|
+
finish({ ok: false, stage: "protocol", error: "VLESS \u54CD\u5E94\u5934\u975E\u6CD5" });
|
|
4557
|
+
return;
|
|
4558
|
+
}
|
|
4559
|
+
headDone = true;
|
|
4560
|
+
buf = buf.subarray(2);
|
|
4561
|
+
}
|
|
4562
|
+
if (headDone && buf.length > 0) {
|
|
4563
|
+
finish({
|
|
4564
|
+
ok: true,
|
|
4565
|
+
stage: "data",
|
|
4566
|
+
firstBytes: buf.subarray(0, 16).toString("latin1")
|
|
4567
|
+
});
|
|
4568
|
+
}
|
|
4569
|
+
});
|
|
4570
|
+
down.end();
|
|
4571
|
+
}, 300);
|
|
4572
|
+
} catch (err) {
|
|
4573
|
+
finish({
|
|
4574
|
+
ok: false,
|
|
4575
|
+
stage,
|
|
4576
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4577
|
+
});
|
|
4578
|
+
}
|
|
4579
|
+
})();
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4362
4582
|
var WindowMeter, USER_AGENT;
|
|
4363
4583
|
var init_true_probe = __esm({
|
|
4364
4584
|
"src/scan/true-probe.ts"() {
|
|
@@ -5330,16 +5550,30 @@ async function runScan(options) {
|
|
|
5330
5550
|
const filtered = maxLatencyMs > 0 ? tcpOk.filter((r) => r.latency <= maxLatencyMs) : tcpOk;
|
|
5331
5551
|
const tlsCandidateLimit = Math.max(effectiveProbeLimit * 4, 600);
|
|
5332
5552
|
const tlsInput = filtered.slice().sort((a, b) => a.latency - b.latency).slice(0, tlsCandidateLimit);
|
|
5553
|
+
const transport = options.probeTransport ?? "ws";
|
|
5554
|
+
const xhttpPath = (options.xhttpPath?.trim() || "/xhttp").replace(/\/+$/, "") || "/xhttp";
|
|
5333
5555
|
report({ type: "stage", stage: 1, name: "TLS \u63E1\u624B\u7B5B\u9009", total: tlsInput.length });
|
|
5334
5556
|
let tlsDone = 0;
|
|
5335
5557
|
const tlsResults = await poolAdaptive(tlsInput, tlsConcurrency, async (item) => {
|
|
5336
|
-
const
|
|
5558
|
+
const doProbe = async (alpn) => await withRetry(
|
|
5337
5559
|
retries,
|
|
5338
|
-
() => probeTlsHandshake(item.ip, options.port, options.host, tlsTimeoutMs),
|
|
5560
|
+
() => probeTlsHandshake(item.ip, options.port, options.host, tlsTimeoutMs, alpn),
|
|
5339
5561
|
(r) => r.tlsMs > 0,
|
|
5340
|
-
// 第 4 个参数:上次失败原因是超时就不要再试
|
|
5341
5562
|
(r) => !isTimeoutError(r.error)
|
|
5342
5563
|
);
|
|
5564
|
+
let probe;
|
|
5565
|
+
if (transport === "xhttp") {
|
|
5566
|
+
probe = await doProbe("h2");
|
|
5567
|
+
} else if (transport === "both") {
|
|
5568
|
+
const h1 = await doProbe("http/1.1");
|
|
5569
|
+
if (h1.tlsMs <= 0) probe = h1;
|
|
5570
|
+
else {
|
|
5571
|
+
const h2 = await doProbe("h2");
|
|
5572
|
+
probe = h2.tlsMs <= 0 ? h2 : { ...h2, tlsMs: Math.max(h1.tlsMs, h2.tlsMs), alpn: "both" };
|
|
5573
|
+
}
|
|
5574
|
+
} else {
|
|
5575
|
+
probe = await doProbe("http/1.1");
|
|
5576
|
+
}
|
|
5343
5577
|
tlsDone++;
|
|
5344
5578
|
if (tlsDone % 200 === 0 || tlsDone === tlsInput.length) {
|
|
5345
5579
|
report({
|
|
@@ -5360,72 +5594,112 @@ async function runScan(options) {
|
|
|
5360
5594
|
countFailure(failures, "tls", item.tls.error);
|
|
5361
5595
|
}
|
|
5362
5596
|
const stage1 = tlsOk.sort((a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency).slice(0, effectiveProbeLimit);
|
|
5597
|
+
const needWs = transport !== "xhttp";
|
|
5598
|
+
const needXhttp = transport !== "ws";
|
|
5363
5599
|
const strictProbe = options.verifyPayload !== false;
|
|
5364
5600
|
const explicitProbePath = options.probePath?.trim();
|
|
5365
5601
|
const explicitWsPath = options.wsPath?.trim();
|
|
5366
|
-
const strictProbePath = explicitProbePath ||
|
|
5367
|
-
|
|
5368
|
-
report({
|
|
5369
|
-
type: "stage",
|
|
5370
|
-
stage: 2,
|
|
5371
|
-
name: strictProbe ? "WS 101 + \u54CD\u5E94\u4F53\u6821\u9A8C\uFF08\u63A2\u9488\u7AEF\u70B9\uFF09" : "WebSocket 101 \u6821\u9A8C",
|
|
5372
|
-
total: stage1.length
|
|
5373
|
-
});
|
|
5602
|
+
const strictProbePath = explicitProbePath || (explicitWsPath?.startsWith("/__edge_probe") ? explicitWsPath : "") || "/__edge_probe";
|
|
5603
|
+
const stage2Name = transport === "xhttp" ? "XHTTP \u7AEF\u70B9\u6821\u9A8C\uFF08H2/packet-up\uFF09" : transport === "both" ? "WS + XHTTP \u53CC\u6808\u6821\u9A8C" : strictProbe ? "WS 101 + \u54CD\u5E94\u4F53\u6821\u9A8C\uFF08\u63A2\u9488\u7AEF\u70B9\uFF09" : "WebSocket 101 \u6821\u9A8C";
|
|
5604
|
+
report({ type: "stage", stage: 2, name: stage2Name, total: stage1.length });
|
|
5374
5605
|
let probeDone = 0;
|
|
5375
5606
|
let verifiedCount = 0;
|
|
5376
5607
|
let pathFailures = 0;
|
|
5377
5608
|
const earlyExitTarget = hasCountryFilter ? Math.ceil(speedLimit * 1.5) : Infinity;
|
|
5378
5609
|
let matchedCount = 0;
|
|
5379
5610
|
let stoppedEarly = false;
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5611
|
+
let wsPool = stage1.map((item) => ({ ...item, colo: "" }));
|
|
5612
|
+
let wsAll = [];
|
|
5613
|
+
let xAll = [];
|
|
5614
|
+
if (needWs) {
|
|
5615
|
+
const probeResults = await pool(
|
|
5616
|
+
wsPool,
|
|
5617
|
+
probeConcurrency,
|
|
5618
|
+
async (item) => {
|
|
5619
|
+
const probeFn = strictProbe ? probeWsPing : probeWs101;
|
|
5620
|
+
const probePath = strictProbe ? strictProbePath : explicitWsPath || "/__edge_probe";
|
|
5621
|
+
const result = await withRetry(
|
|
5622
|
+
retries,
|
|
5623
|
+
() => probeFn(item.ip, options.port, options.host, probeTimeoutMs, probePath)
|
|
5624
|
+
);
|
|
5625
|
+
let pathOk;
|
|
5626
|
+
if (result.ok && explicitWsPath && explicitWsPath !== probePath && options.verifyWsPath !== false) {
|
|
5627
|
+
const pathProbe = await probeWs101(item.ip, options.port, options.host, probeTimeoutMs, explicitWsPath);
|
|
5628
|
+
pathOk = pathProbe.ok;
|
|
5629
|
+
if (!pathOk) pathFailures++;
|
|
5630
|
+
}
|
|
5631
|
+
probeDone++;
|
|
5632
|
+
if (result.pongVerified) verifiedCount++;
|
|
5633
|
+
if (hasCountryFilter && result.ok && countryFilter.includes(countryOfColo(result.colo || ""))) {
|
|
5634
|
+
matchedCount++;
|
|
5635
|
+
}
|
|
5636
|
+
report({
|
|
5637
|
+
type: "progress",
|
|
5638
|
+
stage: 2,
|
|
5639
|
+
done: probeDone,
|
|
5640
|
+
total: stage1.length,
|
|
5641
|
+
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}` : ""}`
|
|
5642
|
+
});
|
|
5643
|
+
options.onObservation?.({ ip: item.ip, ok: result.ok, stage: "ws", error: result.error });
|
|
5644
|
+
return { ...item, probe: result, pathOk, colo: result.colo || "" };
|
|
5645
|
+
},
|
|
5646
|
+
() => {
|
|
5647
|
+
if (matchedCount >= earlyExitTarget) {
|
|
5648
|
+
stoppedEarly = true;
|
|
5649
|
+
return true;
|
|
5650
|
+
}
|
|
5651
|
+
return false;
|
|
5652
|
+
}
|
|
5653
|
+
);
|
|
5654
|
+
wsAll = probeResults;
|
|
5655
|
+
const wsFiltered2 = (strictProbe ? wsAll.filter((r) => r.probe?.ok && r.probe.pongVerified === true) : wsAll.filter((r) => r.probe?.ok)).filter((r) => r.pathOk !== false);
|
|
5656
|
+
for (const item of wsAll) {
|
|
5657
|
+
if (item.probe?.ok) continue;
|
|
5658
|
+
countFailure(failures, "ws101", item.probe?.error);
|
|
5659
|
+
}
|
|
5660
|
+
wsPool = wsFiltered2;
|
|
5661
|
+
}
|
|
5662
|
+
let xhttpOk = wsPool;
|
|
5663
|
+
let xhttpOkCount = 0;
|
|
5664
|
+
if (needXhttp) {
|
|
5665
|
+
report({ type: "stage", stage: 2, name: "XHTTP \u7AEF\u70B9\u6821\u9A8C\uFF08H2/packet-up\uFF09", total: wsPool.length });
|
|
5666
|
+
let xDone = 0;
|
|
5667
|
+
const xResults = await pool(wsPool, probeConcurrency, async (item) => {
|
|
5386
5668
|
const result = await withRetry(
|
|
5387
5669
|
retries,
|
|
5388
|
-
() =>
|
|
5670
|
+
() => probeXhttpEndpoint(item.ip, options.port, options.host, xhttpPath, probeTimeoutMs)
|
|
5389
5671
|
);
|
|
5390
|
-
|
|
5391
|
-
if (result.ok && explicitWsPath && explicitWsPath !== probePath && options.verifyWsPath !== false) {
|
|
5392
|
-
const pathProbe = await probeWs101(item.ip, options.port, options.host, probeTimeoutMs, explicitWsPath);
|
|
5393
|
-
pathOk = pathProbe.ok;
|
|
5394
|
-
if (!pathOk) pathFailures++;
|
|
5395
|
-
}
|
|
5396
|
-
probeDone++;
|
|
5397
|
-
if (result.pongVerified) verifiedCount++;
|
|
5398
|
-
if (hasCountryFilter && result.ok && countryFilter.includes(countryOfColo(result.colo || ""))) {
|
|
5399
|
-
matchedCount++;
|
|
5400
|
-
}
|
|
5672
|
+
xDone++;
|
|
5401
5673
|
report({
|
|
5402
5674
|
type: "progress",
|
|
5403
5675
|
stage: 2,
|
|
5404
|
-
done:
|
|
5405
|
-
total:
|
|
5406
|
-
message:
|
|
5676
|
+
done: xDone,
|
|
5677
|
+
total: wsPool.length,
|
|
5678
|
+
message: `XHTTP \u6821\u9A8C ${xDone}/${wsPool.length}${result.ok ? ` \u2713 ${result.colo}` : ` \u2717 ${result.error ?? ""}`}`
|
|
5407
5679
|
});
|
|
5408
|
-
options.onObservation?.({ ip: item.ip, ok: result.ok, stage: "
|
|
5409
|
-
return { ...item,
|
|
5410
|
-
}
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5680
|
+
options.onObservation?.({ ip: item.ip, ok: result.ok, stage: "xhttp", error: result.error });
|
|
5681
|
+
return { ...item, xhttp: result, colo: item.colo || result.colo || "" };
|
|
5682
|
+
});
|
|
5683
|
+
xAll = xResults;
|
|
5684
|
+
for (const item of xAll) {
|
|
5685
|
+
if (!item.xhttp?.ok) countFailure(failures, "xhttp", item.xhttp?.error);
|
|
5686
|
+
}
|
|
5687
|
+
xhttpOk = xAll.filter((r) => r.xhttp?.ok);
|
|
5688
|
+
xhttpOkCount = xhttpOk.length;
|
|
5689
|
+
} else {
|
|
5690
|
+
xhttpOkCount = wsPool.length;
|
|
5691
|
+
}
|
|
5692
|
+
const wsOk = xhttpOk;
|
|
5693
|
+
for (const item of wsOk) {
|
|
5694
|
+
if (!item.probe && item.xhttp) {
|
|
5695
|
+
item.probe = { ok: true, colo: item.colo, status: item.xhttp.status, latencyMs: item.xhttp.latencyMs };
|
|
5417
5696
|
}
|
|
5418
|
-
);
|
|
5419
|
-
const wsOk = (strictProbe ? probeResults.filter((r) => r.probe.ok && r.probe.pongVerified === true) : probeResults.filter((r) => r.probe.ok)).filter((r) => r.pathOk !== false);
|
|
5420
|
-
for (const item of probeResults) {
|
|
5421
|
-
if (item.probe.ok) continue;
|
|
5422
|
-
countFailure(failures, "ws101", item.probe.error);
|
|
5423
5697
|
}
|
|
5424
5698
|
let tunnelOk = wsOk;
|
|
5425
5699
|
let tunnelFailed = 0;
|
|
5426
5700
|
const tunnelCredential = options.uuid || options.trojanPassword;
|
|
5427
|
-
if (tunnelCredential && options.wsPath) {
|
|
5428
|
-
const candidates2 =
|
|
5701
|
+
if (needWs && tunnelCredential && options.wsPath) {
|
|
5702
|
+
const candidates2 = tunnelOk.slice(0, speedLimit);
|
|
5429
5703
|
const verified = await pool(candidates2, 4, async (item) => {
|
|
5430
5704
|
const result = await verifyTunnel({
|
|
5431
5705
|
ip: item.ip,
|
|
@@ -5448,14 +5722,41 @@ async function runScan(options) {
|
|
|
5448
5722
|
return { item, ok: result.ok };
|
|
5449
5723
|
});
|
|
5450
5724
|
const passed = new Set(verified.filter((v) => v.ok).map((v) => v.item.ip));
|
|
5451
|
-
tunnelOk =
|
|
5725
|
+
tunnelOk = tunnelOk.filter((item) => passed.has(item.ip));
|
|
5452
5726
|
if (tunnelOk.length === 0) tunnelOk = wsOk;
|
|
5453
5727
|
}
|
|
5728
|
+
if (needXhttp && options.uuid) {
|
|
5729
|
+
const candidates2 = tunnelOk.slice(0, speedLimit);
|
|
5730
|
+
const verified = await pool(candidates2, 4, async (item) => {
|
|
5731
|
+
const result = await verifyXhttpTunnel({
|
|
5732
|
+
ip: item.ip,
|
|
5733
|
+
port: options.port,
|
|
5734
|
+
host: options.host,
|
|
5735
|
+
xhttpPath,
|
|
5736
|
+
uuid: options.uuid,
|
|
5737
|
+
targetHost: options.verifyTargetHost,
|
|
5738
|
+
targetPort: options.verifyTargetPort
|
|
5739
|
+
});
|
|
5740
|
+
if (!result.ok) tunnelFailed++;
|
|
5741
|
+
report({
|
|
5742
|
+
type: "progress",
|
|
5743
|
+
stage: 2,
|
|
5744
|
+
done: candidates2.length,
|
|
5745
|
+
total: candidates2.length,
|
|
5746
|
+
message: `XHTTP \u96A7\u9053\u6821\u9A8C ${result.ok ? "\u2713" : "\u2717 " + (result.error ?? "")}`
|
|
5747
|
+
});
|
|
5748
|
+
return { item, ok: result.ok };
|
|
5749
|
+
});
|
|
5750
|
+
const passed = new Set(verified.filter((v) => v.ok).map((v) => v.item.ip));
|
|
5751
|
+
const before = tunnelOk.length;
|
|
5752
|
+
tunnelOk = tunnelOk.filter((item) => passed.has(item.ip));
|
|
5753
|
+
if (tunnelOk.length === 0 && before > 0) tunnelOk = wsOk;
|
|
5754
|
+
}
|
|
5454
5755
|
let wsFiltered = wsOk;
|
|
5455
5756
|
let appliedCountries = [];
|
|
5456
5757
|
let countryFilterRelaxed = false;
|
|
5457
5758
|
if (hasCountryFilter && wsOk.length > 0) {
|
|
5458
|
-
const matched = wsOk.filter((r) => countryFilter.includes(countryOfColo(r.probe
|
|
5759
|
+
const matched = wsOk.filter((r) => countryFilter.includes(countryOfColo(r.colo || r.probe?.colo || "")));
|
|
5459
5760
|
if (matched.length > 0) {
|
|
5460
5761
|
wsFiltered = matched;
|
|
5461
5762
|
appliedCountries = countryFilter;
|
|
@@ -5528,7 +5829,7 @@ async function runScan(options) {
|
|
|
5528
5829
|
stage: 3,
|
|
5529
5830
|
done: speedDone,
|
|
5530
5831
|
total: stage2.length,
|
|
5531
|
-
message: `\u6D4B\u901F ${speedDone}/${stage2.length} [${item.probe
|
|
5832
|
+
message: `\u6D4B\u901F ${speedDone}/${stage2.length} [${item.colo || item.probe?.colo || "UNK"}] ${result.steadyMBps.toFixed(1)} MB/s${jitter > 0 ? ` \xB1${jitter.toFixed(1)}` : ""}`
|
|
5532
5833
|
});
|
|
5533
5834
|
return { ...item, speed: result.ok ? result.steadyMBps : 0, peakMBps: result.peakMBps, jitter };
|
|
5534
5835
|
});
|
|
@@ -5568,7 +5869,7 @@ async function runScan(options) {
|
|
|
5568
5869
|
stage: 3,
|
|
5569
5870
|
done: speedDone,
|
|
5570
5871
|
total: stage2.length,
|
|
5571
|
-
message: `\u6D4B\u901F ${speedDone}/${stage2.length} [${item.probe
|
|
5872
|
+
message: `\u6D4B\u901F ${speedDone}/${stage2.length} [${item.colo || item.probe?.colo || "UNK"}] ${result.steadyMBps.toFixed(1)} MB/s${jitter > 0 ? ` \xB1${jitter.toFixed(1)}` : ""}`
|
|
5572
5873
|
});
|
|
5573
5874
|
return { ...item, speed: result.ok ? result.steadyMBps : 0, peakMBps: result.peakMBps, jitter };
|
|
5574
5875
|
});
|
|
@@ -5577,7 +5878,7 @@ async function runScan(options) {
|
|
|
5577
5878
|
ip: r.ip,
|
|
5578
5879
|
family: r.ip.includes(":") ? "v6" : "v4",
|
|
5579
5880
|
port: options.port,
|
|
5580
|
-
colo: r.probe
|
|
5881
|
+
colo: r.colo || r.probe?.colo || "UNK",
|
|
5581
5882
|
latency: r.latency,
|
|
5582
5883
|
// tcpMs 是阶段一测得的 TCP 建连耗时(CLI 的 latency 字段本身就是它,
|
|
5583
5884
|
// 这里显式补一份,便于与桌面版报告字段一一对应)。
|
|
@@ -5627,14 +5928,21 @@ async function runScan(options) {
|
|
|
5627
5928
|
for (const item of tlsResults) {
|
|
5628
5929
|
observations.push({ ip: item.ip, ok: item.tls.tlsMs > 0, stage: "tls", latencyMs: item.tls.tlsMs });
|
|
5629
5930
|
}
|
|
5630
|
-
for (const item of
|
|
5931
|
+
for (const item of wsAll) {
|
|
5932
|
+
const pr = item.probe;
|
|
5933
|
+
if (!pr) continue;
|
|
5631
5934
|
observations.push({
|
|
5632
5935
|
ip: item.ip,
|
|
5633
|
-
ok:
|
|
5936
|
+
ok: pr.ok && pr.pongVerified !== false,
|
|
5634
5937
|
stage: "ws",
|
|
5635
5938
|
latencyMs: item.latency
|
|
5636
5939
|
});
|
|
5637
5940
|
}
|
|
5941
|
+
for (const item of xAll) {
|
|
5942
|
+
const xr = item.xhttp;
|
|
5943
|
+
if (!xr) continue;
|
|
5944
|
+
observations.push({ ip: item.ip, ok: xr.ok, stage: "xhttp", latencyMs: xr.latencyMs });
|
|
5945
|
+
}
|
|
5638
5946
|
const speedByIp = /* @__PURE__ */ new Map();
|
|
5639
5947
|
for (const item of speedResults) {
|
|
5640
5948
|
if (item.speed && item.speed > 0) speedByIp.set(item.ip, item.speed);
|
|
@@ -5651,6 +5959,7 @@ async function runScan(options) {
|
|
|
5651
5959
|
tcpOk: tcpOk.length,
|
|
5652
5960
|
tlsOk: tlsOk.length,
|
|
5653
5961
|
wsOk: wsOk.length,
|
|
5962
|
+
xhttpOk: xhttpOkCount,
|
|
5654
5963
|
verified: verifiedCount,
|
|
5655
5964
|
speedOk: entries.length,
|
|
5656
5965
|
elapsedMs: Date.now() - started,
|
|
@@ -6572,7 +6881,7 @@ var init_network_profile = __esm({
|
|
|
6572
6881
|
MAX_COUNTER = 1e9;
|
|
6573
6882
|
MAX_FILE_BYTES = 4 * 1024 * 1024;
|
|
6574
6883
|
DEFAULT_HALF_LIFE = 7 * 24 * 60 * 60 * 1e3;
|
|
6575
|
-
STAGES = ["tcp", "tls", "ws", "speed"];
|
|
6884
|
+
STAGES = ["tcp", "tls", "ws", "xhttp", "speed"];
|
|
6576
6885
|
FAILURE_CLASSES = ["timeout", "refused", "unreachable", "reset", "tls", "alpn", "dns", "http", "content", "cancelled", "unknown"];
|
|
6577
6886
|
record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6578
6887
|
finite = (value) => typeof value === "number" && Number.isFinite(value);
|
|
@@ -7073,7 +7382,7 @@ async function resolveScanCandidates(body) {
|
|
|
7073
7382
|
return { candidates: plan.candidates, source: "generated", family: plan.family, note: plan.note };
|
|
7074
7383
|
}
|
|
7075
7384
|
function describePlan(plan) {
|
|
7076
|
-
if (plan.source === "manual") return `\u4F7F\u7528\
|
|
7385
|
+
if (plan.source === "manual") return `\u4F7F\u7528\u624B\u52A8\u6307\u5B9A\u7684 ${plan.candidates.length} \u4E2A\u5019\u9009 IP`;
|
|
7077
7386
|
if (plan.source === "request") return `\u4F7F\u7528\u8BF7\u6C42\u643A\u5E26\u7684 ${plan.candidates.length} \u4E2A\u5019\u9009 IP`;
|
|
7078
7387
|
const note = plan.note ? `\uFF08${plan.note}\uFF09` : "";
|
|
7079
7388
|
return `\u5DF2\u81EA\u52A8\u751F\u6210 ${plan.candidates.length} \u4E2A\u5019\u9009 IP${note}`;
|
|
@@ -7303,7 +7612,9 @@ async function handleRequest(req, res) {
|
|
|
7303
7612
|
// 阶段二会硬连默认探针路径 → 全军覆没
|
|
7304
7613
|
// verifyPayload —— 目标没有探针端点时,内容校验必然失败,
|
|
7305
7614
|
// 应自动退回纯 101 校验
|
|
7306
|
-
// speedMode / speedUrl ——
|
|
7615
|
+
// speedMode / speedUrl —— 调用方可以指定用探针端点还是公开测速地址
|
|
7616
|
+
probeTransport: body.probeTransport,
|
|
7617
|
+
xhttpPath: body.xhttpPath,
|
|
7307
7618
|
wsPath: body.wsPath,
|
|
7308
7619
|
probePath: body.probePath,
|
|
7309
7620
|
verifyPayload: body.verifyPayload,
|
|
@@ -7406,7 +7717,7 @@ CFPilot \u672C\u5730\u771F\u8FDE\u63A5\u4F18\u9009\u5668 \u2014\u2014 \u7528\u4F
|
|
|
7406
7717
|
${NAME} scan [\u9009\u9879] \u6267\u884C\u4E09\u9636\u4F18\u9009\u626B\u63CF
|
|
7407
7718
|
${NAME} scan compare \u53CC\u6808\u5BF9\u7167\u62A5\u544A\uFF08IPv4 vs IPv6\uFF0C\u540C\u53C2\u6570\u8DD1\u4E24\u8F6E\uFF09
|
|
7408
7719
|
${NAME} scan relay \u53CD\u4EE3\u5165\u53E3\u5019\u9009\u7684\u51FA\u7AD9\u4F53\u68C0\uFF08\u4ECE Worker \u5185\u90E8\u53D1\u8D77\uFF09
|
|
7409
|
-
${NAME} scan serve [\u9009\u9879] \u542F\u52A8\u672C\u5730\u6865\u63A5\u670D\u52A1\
|
|
7720
|
+
${NAME} scan serve [\u9009\u9879] \u542F\u52A8\u672C\u5730\u6865\u63A5\u670D\u52A1\uFF08HTTP \u63A5\u53E3\uFF0C\u4F9B\u811A\u672C\u9A71\u52A8\u626B\u63CF\uFF09
|
|
7410
7721
|
${NAME} scan ips [\u9009\u9879] \u6253\u5370 Cloudflare \u5B98\u65B9\u7F51\u6BB5
|
|
7411
7722
|
${NAME} --help \u663E\u793A\u5E2E\u52A9
|
|
7412
7723
|
${NAME} --version \u663E\u793A\u7248\u672C
|
|
@@ -7422,6 +7733,10 @@ scan \u9009\u9879:
|
|
|
7422
7733
|
--no-callback \u53EA\u6253\u5370\u7ED3\u679C\uFF0C\u4E0D\u56DE\u586B
|
|
7423
7734
|
--path <path> \u9636\u6BB5\u4E8C\u6821\u9A8C\u7684 WebSocket \u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /__edge_probe
|
|
7424
7735
|
\uFF08\u5BF9\u63A5\u5176\u5B83\u9879\u76EE\u65F6\u586B\u5B83\u81EA\u5DF1\u7684 WS \u8DEF\u5F84\uFF0C\u4F8B\u5982 /vless \u6216 /<uuid>\uFF09
|
|
7736
|
+
--probe-transport <m> \u63A2\u6D4B\u4F20\u8F93\u5206\u7C7B\uFF1Aws|xhttp|both\uFF0C\u9ED8\u8BA4 ws
|
|
7737
|
+
ws = \u53EA\u9A8C WS\uFF08H1/101\uFF09\uFF0Cxhttp = \u53EA\u9A8C XHTTP\uFF08H2/packet-up\uFF09\uFF0Cboth = \u4E24\u8005\u90FD\u8981
|
|
7738
|
+
\u8BA2\u9605\u542B VLESS+XHTTP \u65F6\u7528 xhttp \u6216 both\uFF1B\u9009 xhttp \u4F1A\u8DF3\u8FC7 WS \u907F\u514D\u8BEF\u6740
|
|
7739
|
+
--xhttp-path <path> XHTTP \u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /xhttp\uFF08\u4E0E\u6570\u636E\u9762\u4E00\u81F4\uFF0C--probe-transport=xhttp/both \u65F6\u751F\u6548\uFF09
|
|
7425
7740
|
--probe-path <path> probe \u6A21\u5F0F\u7684\u6D4B\u901F\u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /__edge_probe
|
|
7426
7741
|
\u663E\u5F0F\u6307\u5B9A\u540E\uFF0C\u9636\u6BB5\u4E8C\u7684\u5185\u5BB9\u6821\u9A8C\u4E5F\u4F1A\u8D70\u8FD9\u4E2A\u8DEF\u5F84
|
|
7427
7742
|
\uFF08\u5BF9\u63A5\u7B2C\u4E09\u65B9\u9879\u76EE\u65F6\u7528\uFF1B\u63A2\u9488\u7AEF\u70B9\u4E0D\u662F /__edge_probe \u65F6\u5FC5\u586B\uFF09
|
|
@@ -9145,7 +9460,7 @@ async function runScanCommand(args) {
|
|
|
9145
9460
|
` ${NAME} \u672C\u5730\u6865\u63A5\u670D\u52A1\u5DF2\u542F\u52A8`,
|
|
9146
9461
|
` \u76D1\u542C\u5730\u5740\uFF1Ahttp://${host2}:${handle.port}`,
|
|
9147
9462
|
` \u7248\u672C\uFF1Av${BRIDGE_VERSION2}`,
|
|
9148
|
-
" \
|
|
9463
|
+
" \u53EF\u7528 HTTP \u63A5\u53E3\uFF1AGET /status\u3001POST /start-scan\u3001GET /events\u3001GET /results",
|
|
9149
9464
|
" \u6309 Ctrl+C \u9000\u51FA\u3002",
|
|
9150
9465
|
""
|
|
9151
9466
|
].join("\n")
|
|
@@ -9172,6 +9487,12 @@ async function runScanCommand(args) {
|
|
|
9172
9487
|
const askCallback = flagBool(args, "ask-callback");
|
|
9173
9488
|
const wsPath = normalizeWsPath(flagString(args, "path"), "/__edge_probe");
|
|
9174
9489
|
const probePath = normalizeWsPath(flagString(args, "probe-path"), "/__edge_probe");
|
|
9490
|
+
const probeTransportRaw = (flagString(args, "probe-transport") || "ws").trim().toLowerCase();
|
|
9491
|
+
const probeTransport = probeTransportRaw === "xhttp" || probeTransportRaw === "both" ? probeTransportRaw : "ws";
|
|
9492
|
+
const xhttpPath = normalizeWsPath(
|
|
9493
|
+
flagString(args, "xhttp-path") || "/xhttp",
|
|
9494
|
+
"/xhttp"
|
|
9495
|
+
).replace(/\/+$/, "") || "/xhttp";
|
|
9175
9496
|
const noSpeed = flagBool(args, "no-speed");
|
|
9176
9497
|
const countries = normalizeCountryFilter(flagList(args, "countries"));
|
|
9177
9498
|
const panelHost = flagString(args, "panel");
|
|
@@ -9208,6 +9529,8 @@ ${NAME} v${VERSION}
|
|
|
9208
9529
|
process.stdout.write(`\u76EE\u6807\u57DF\u540D\uFF1A${host}:${port}\uFF08\u5C06\u4F5C\u4E3A TLS SNI \u4E0E HTTP Host\uFF09
|
|
9209
9530
|
`);
|
|
9210
9531
|
process.stdout.write(`WS \u8DEF\u5F84\uFF1A${wsPath}
|
|
9532
|
+
`);
|
|
9533
|
+
process.stdout.write(`\u63A2\u6D4B\u4F20\u8F93\uFF1A${probeTransport}${probeTransport !== "ws" ? `\uFF08XHTTP \u8DEF\u5F84\uFF1A${xhttpPath}\uFF09` : ""}
|
|
9211
9534
|
`);
|
|
9212
9535
|
if (countries.length > 0) {
|
|
9213
9536
|
process.stdout.write(`\u56FD\u5BB6\u7B5B\u9009\uFF1A${countries.join(" / ")}\uFF08\u4E0D\u586B\u5219\u5168\u91CF\uFF09
|
|
@@ -9321,6 +9644,8 @@ ${NAME} v${VERSION}
|
|
|
9321
9644
|
port,
|
|
9322
9645
|
candidates,
|
|
9323
9646
|
countries,
|
|
9647
|
+
probeTransport,
|
|
9648
|
+
xhttpPath,
|
|
9324
9649
|
wsPath,
|
|
9325
9650
|
probePath,
|
|
9326
9651
|
skipSpeed,
|
|
@@ -9395,6 +9720,8 @@ ${NAME} v${VERSION}
|
|
|
9395
9720
|
port,
|
|
9396
9721
|
wsPath,
|
|
9397
9722
|
probePath,
|
|
9723
|
+
probeTransport,
|
|
9724
|
+
xhttpPath,
|
|
9398
9725
|
sample: flagNumber(args, "sample", 6556),
|
|
9399
9726
|
top,
|
|
9400
9727
|
countries: summary.stats.countries,
|