mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 13:50:29 +08:00
201 lines
6.7 KiB
JavaScript
201 lines
6.7 KiB
JavaScript
'use strict';const fetchTextByLine=require('./fetch-text-by-line.YY5b5610.cjs'),index=require('./index.B8Uk9n3v.cjs'),require$$2=require('fast-cidr-tools'),memoPromise=require('./memo-promise.BbOsVeGo.cjs'),base=require('./base.C13YY5P3.cjs'),fsMemo=require('./fs-memo.Dw823m02.cjs');var buildChnCidr = {exports: {}};var cidr = {};var hasRequiredCidr;
|
|
|
|
function requireCidr () {
|
|
if (hasRequiredCidr) return cidr;
|
|
hasRequiredCidr = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
CN_CIDR_MISSING_IN_CHNROUTE: function() {
|
|
return CN_CIDR_MISSING_IN_CHNROUTE;
|
|
},
|
|
NON_CN_CIDR_INCLUDED_IN_CHNROUTE: function() {
|
|
return NON_CN_CIDR_INCLUDED_IN_CHNROUTE;
|
|
},
|
|
RESERVED_IPV4_CIDR: function() {
|
|
return RESERVED_IPV4_CIDR;
|
|
}
|
|
});
|
|
const RESERVED_IPV4_CIDR = [
|
|
'0.0.0.0/8',
|
|
'10.0.0.0/8',
|
|
'100.64.0.0/10',
|
|
'127.0.0.0/8',
|
|
'169.254.0.0/16',
|
|
'172.16.0.0/12',
|
|
'192.0.0.0/24',
|
|
'192.0.2.0/24',
|
|
// 192.88.99.0 // is currently being broadcast by HE and Comcast
|
|
'192.168.0.0/16',
|
|
'198.18.0.0/15',
|
|
'198.51.100.0/24',
|
|
'203.0.113.0/24',
|
|
'224.0.0.0/4',
|
|
'233.252.0.0/24',
|
|
'240.0.0.0/4'
|
|
];
|
|
const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [
|
|
'223.118.0.0/15',
|
|
'223.120.0.0/15'
|
|
];
|
|
const CN_CIDR_MISSING_IN_CHNROUTE = [
|
|
// Baidu Public DNS
|
|
'180.76.76.0/24',
|
|
// Ali Public DNS
|
|
'223.5.5.0/24',
|
|
'223.6.6.0/24',
|
|
// Tencent DNSPod Public DNS
|
|
'119.29.29.0/24',
|
|
'119.28.28.0/24',
|
|
'120.53.53.0/24',
|
|
'1.12.12.0/24',
|
|
'1.12.34.0/24',
|
|
// ByteDance Public DNS
|
|
'180.184.1.0/24',
|
|
'180.184.2.0/24',
|
|
// 360 Public DNS
|
|
'101.198.198.0/24',
|
|
'101.198.199.0/24',
|
|
// ChinaTelecom
|
|
'103.7.141.0/24',
|
|
// Aliyun Shenzhen
|
|
'120.78.0.0/16',
|
|
// wy.com.cn
|
|
'211.99.96.0/19',
|
|
// AS58593, Azure China
|
|
'40.72.0.0/15',
|
|
'42.159.0.0/16',
|
|
'52.130.0.0/17',
|
|
'52.131.0.0/16',
|
|
'103.9.8.0/22',
|
|
'139.217.0.0/16',
|
|
'139.219.0.0/16',
|
|
'143.64.0.0/16',
|
|
'159.27.0.0/16',
|
|
'163.228.0.0/16',
|
|
// NetEase
|
|
'223.252.194.0/24',
|
|
'223.252.196.0/24',
|
|
// Xiamen Kuaikuai
|
|
'180.188.36.0/22' // no route globally
|
|
];
|
|
} (cidr));
|
|
return cidr;
|
|
}var ip = {};var hasRequiredIp;
|
|
|
|
function requireIp () {
|
|
if (hasRequiredIp) return ip;
|
|
hasRequiredIp = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "IPListOutput", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return IPListOutput;
|
|
}
|
|
});
|
|
const _clash = /*@__PURE__*/ base.c();
|
|
const _singbox = /*@__PURE__*/ base.f();
|
|
const _surge = /*@__PURE__*/ base.e();
|
|
const _base = /*@__PURE__*/ base.b();
|
|
class IPListOutput extends _base.FileOutput {
|
|
clashUseRule;
|
|
strategies;
|
|
constructor(span, id, clashUseRule = true){
|
|
super(span, id), this.clashUseRule = clashUseRule;
|
|
this.strategies = [
|
|
new _surge.SurgeRuleSet('ip'),
|
|
this.clashUseRule ? new _clash.ClashClassicRuleSet('ip') : new _clash.ClashIPSet(),
|
|
new _singbox.SingboxSource('ip')
|
|
];
|
|
}
|
|
}
|
|
} (ip));
|
|
return ip;
|
|
}var hasRequiredBuildChnCidr;
|
|
|
|
function requireBuildChnCidr () {
|
|
if (hasRequiredBuildChnCidr) return buildChnCidr.exports;
|
|
hasRequiredBuildChnCidr = 1;
|
|
(function (module, exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
buildChnCidr: function() {
|
|
return buildChnCidr;
|
|
},
|
|
getChnCidrPromise: function() {
|
|
return getChnCidrPromise;
|
|
}
|
|
});
|
|
const _fetchtextbyline = /*@__PURE__*/ fetchTextByLine.a();
|
|
const _trace = /*@__PURE__*/ index.r();
|
|
const _fastcidrtools = require$$2;
|
|
const _memopromise = /*@__PURE__*/ memoPromise.r();
|
|
const _cidr = /*@__PURE__*/ requireCidr();
|
|
const _appendarrayinplace = /*@__PURE__*/ base.a();
|
|
const _ip = /*@__PURE__*/ requireIp();
|
|
const _fsmemo = /*@__PURE__*/ fsMemo.r();
|
|
const _description = /*@__PURE__*/ base.r();
|
|
const PROBE_CHN_CIDR_V4 = [
|
|
// NetEase Hangzhou
|
|
'223.252.196.38',
|
|
// Aliyun ShenZhen
|
|
'120.78.92.171'
|
|
];
|
|
const getChnCidrPromise = (0, _memopromise.createMemoizedPromise)((0, _fsmemo.cachedOnlyFail)(async function getChnCidr() {
|
|
const [_cidr4, cidr6] = await Promise.all([
|
|
(0, _fetchtextbyline.fetchRemoteTextByLine)('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync),
|
|
(0, _fetchtextbyline.fetchRemoteTextByLine)('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync)
|
|
]);
|
|
const cidr4 = (0, _fastcidrtools.exclude)((0, _appendarrayinplace.appendArrayInPlace)(_cidr4, _cidr.CN_CIDR_MISSING_IN_CHNROUTE), _cidr.NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true);
|
|
for (const probeIp of PROBE_CHN_CIDR_V4){
|
|
if (!(0, _fastcidrtools.contains)(cidr4, PROBE_CHN_CIDR_V4)) {
|
|
const err = new TypeError('chnroutes missing probe IP');
|
|
err.cause = probeIp;
|
|
throw err;
|
|
}
|
|
}
|
|
return [
|
|
cidr4,
|
|
cidr6
|
|
];
|
|
}, {
|
|
serializer: JSON.stringify,
|
|
deserializer: JSON.parse
|
|
}));
|
|
const buildChnCidr = (0, _trace.task)(require.main === module, __filename)(async (span)=>{
|
|
const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
|
// Can not use SHARED_DESCRIPTION here as different license
|
|
const description = (0, _description.createFileDescription)('CC BY-SA 2.0');
|
|
return Promise.all([
|
|
new _ip.IPListOutput(span, 'china_ip', false).withTitle('Sukka\'s Ruleset - Mainland China IPv4 CIDR').withDescription([
|
|
...description,
|
|
'Data from https://misaka.io (misakaio @ GitHub)'
|
|
]).bulkAddCIDR4(filteredCidr4).write(),
|
|
new _ip.IPListOutput(span, 'china_ip_ipv6', false).withTitle('Sukka\'s Ruleset - Mainland China IPv6 CIDR').withDescription([
|
|
...description,
|
|
'Data from https://github.com/gaoyifan/china-operator-ip'
|
|
]).bulkAddCIDR6(cidr6).write()
|
|
]);
|
|
});
|
|
} (buildChnCidr, buildChnCidr.exports));
|
|
return buildChnCidr.exports;
|
|
}exports.r=requireBuildChnCidr; |