feat: IP4P 合并进 IPv6; ProxyUtils 中增加 ipAddress

This commit is contained in:
xream
2024-07-18 18:35:22 +08:00
parent cddd1818fe
commit fea9de4fae
6 changed files with 51 additions and 16 deletions

View File

@@ -2,7 +2,13 @@ import { Buffer } from 'buffer';
import rs from '@/utils/rs';
import YAML from '@/utils/yaml';
import download from '@/utils/download';
import { isIPv4, isIPv6, isValidPortNumber, isNotBlank } from '@/utils';
import {
isIPv4,
isIPv6,
isValidPortNumber,
isNotBlank,
ipAddress,
} from '@/utils';
import PROXY_PROCESSORS, { ApplyProcessor } from './processors';
import PROXY_PREPROCESSORS from './preprocessors';
import PROXY_PRODUCERS from './producers';
@@ -267,6 +273,7 @@ export const ProxyUtils = {
parse,
process: processFn,
produce,
ipAddress,
isIPv4,
isIPv6,
isIP,

View File

@@ -1,6 +1,6 @@
import resourceCache from '@/utils/resource-cache';
import scriptResourceCache from '@/utils/script-resource-cache';
import { isIPv4, isIPv6 } from '@/utils';
import { isIPv4, isIPv6, ipAddress } from '@/utils';
import { FULL } from '@/utils/logical';
import { getFlag, removeFlag } from '@/utils/geo';
import { doh } from '@/utils/dns';
@@ -360,10 +360,11 @@ function ScriptOperator(script, targetPlatform, $arguments, source) {
};
}
function parseIP4P(IP4P) {
function parseIP4P(ip) {
let server;
let port;
try {
const IP4P = new ipAddress.Address6(ip).correctForm();
if (!/^2001::[^:]+:[^:]+:[^:]+$/.test(IP4P)) {
throw new Error(`Invalid IP4P: ${IP4P}`);
}
@@ -629,7 +630,7 @@ function ResolveDomainOperator({
)
]
: results[p.server];
if (_type === 'IP4P') {
if (type === 'IPv6' && isIPv6(ip)) {
const { server, port } = parseIP4P(ip);
if (server && port) {
p._domain = p.server;