Skip to content

Commit afe00df

Browse files
committed
feat: 处理端口跳跃(感谢亚托莉佬)
1 parent 317a804 commit afe00df

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.14.353",
3+
"version": "2.14.356",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/core/proxy-utils/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isValidPortNumber,
99
isNotBlank,
1010
ipAddress,
11+
getRandomPort,
1112
} from '@/utils';
1213
import PROXY_PROCESSORS, { ApplyProcessor } from './processors';
1314
import PROXY_PREPROCESSORS from './preprocessors';
@@ -220,6 +221,17 @@ function produce(proxies, targetPlatform, type, opts = {}) {
220221
delete proxy['tls-fingerprint'];
221222
}
222223
}
224+
225+
// 处理 端口跳跃
226+
if (proxy.ports) {
227+
// if (!['ClashMeta'].includes(targetPlatform)) {
228+
// proxy.ports = proxy.ports.replace(/\//g, ',');
229+
// }
230+
if (!proxy.port) {
231+
proxy.port = getRandomPort(proxy.ports);
232+
}
233+
}
234+
223235
return proxy;
224236
});
225237

@@ -274,6 +286,7 @@ export const ProxyUtils = {
274286
process: processFn,
275287
produce,
276288
ipAddress,
289+
getRandomPort,
277290
isIPv4,
278291
isIPv6,
279292
isIP,

backend/src/utils/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ function getPolicyDescriptor(str) {
9494
// };
9595
// })();
9696

97+
function getRandomInt(min, max) {
98+
min = Math.ceil(min);
99+
max = Math.floor(max);
100+
return Math.floor(Math.random() * (max - min + 1)) + min;
101+
}
102+
103+
function getRandomPort(portString) {
104+
let portParts = portString.split(/,|\//);
105+
let randomPart = portParts[Math.floor(Math.random() * portParts.length)];
106+
if (randomPart.includes('-')) {
107+
let [min, max] = randomPart.split('-').map(Number);
108+
return getRandomInt(min, max);
109+
} else {
110+
return Number(randomPart);
111+
}
112+
}
113+
97114
export {
98115
ipAddress,
99116
isIPv4,
@@ -105,4 +122,5 @@ export {
105122
getIfPresent,
106123
// utf8ArrayToStr,
107124
getPolicyDescriptor,
125+
getRandomPort,
108126
};

scripts/demo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function operator(proxies = [], targetPlatform, context) {
4242
// parse, // 订阅解析
4343
// process, // 节点操作/文件操作
4444
// produce, // 输出订阅
45+
// getRandomPort, // 获取随机端口(参考 ports 端口跳跃的格式 443,8443,5000-6000)
4546
// ipAddress, // https://github.com/beaugunderson/ip-address
4647
// isIPv4,
4748
// isIPv6,

0 commit comments

Comments
 (0)