Update China IPv4

This commit is contained in:
SukkaW 2024-10-20 21:58:06 +08:00
parent 70df7d33c6
commit 8e2644ac6c
2 changed files with 38 additions and 21 deletions

View File

@ -2,32 +2,42 @@ import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
import { processLineFromReadline } from './lib/process-line';
import { task } from './trace';
import { contains, exclude } from 'fast-cidr-tools';
import { contains as containsCidr, exclude as excludeCidr } from 'fast-cidr-tools';
import { createMemoizedPromise } from './lib/memo-promise';
import { CN_CIDR_NOT_INCLUDED_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
import { appendArrayInPlace } from './lib/append-array-in-place';
import { IPListOutput } from './lib/create-file';
import { cachedOnlyFail } from './lib/fs-memo';
const PROBE_CHN_CIDR = [
const PROBE_CHN_CIDR_V4 = [
// NetEase Hangzhou
'223.252.196.38'
'223.252.196.38',
// Aliyun ShenZhen
'120.78.92.171'
];
export const getChnCidrPromise = createMemoizedPromise(cachedOnlyFail(
async function getChnCidr() {
const [cidr4, cidr6] = await Promise.all([
const [_cidr4, cidr6] = await Promise.all([
fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt').then(processLineFromReadline),
fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt').then(processLineFromReadline)
]);
appendArrayInPlace(cidr4, CN_CIDR_NOT_INCLUDED_IN_CHNROUTE);
const cidr4 = excludeCidr(
appendArrayInPlace(_cidr4, CN_CIDR_MISSING_IN_CHNROUTE),
NON_CN_CIDR_INCLUDED_IN_CHNROUTE,
true
);
if (!contains(cidr4, PROBE_CHN_CIDR)) {
throw new TypeError('chnroutes missing probe IP');
for (const probeIp of PROBE_CHN_CIDR_V4) {
if (!containsCidr(cidr4, PROBE_CHN_CIDR_V4)) {
const err = new TypeError('chnroutes missing probe IP');
err.cause = probeIp;
throw err;
}
}
return [exclude(cidr4, NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true), cidr6] as const;
return [cidr4, cidr6] as const;
},
{
serializer: JSON.stringify,

View File

@ -25,7 +25,8 @@ export const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [
];
// https://github.com/misakaio/chnroutes2/issues/46
export const CN_CIDR_NOT_INCLUDED_IN_CHNROUTE = [
// https://github.com/misakaio/chnroutes2/issues/48
export const CN_CIDR_MISSING_IN_CHNROUTE = [
// Baidu Public DNS
'180.76.76.0/24',
// Ali Public DNS
@ -44,19 +45,25 @@ export const CN_CIDR_NOT_INCLUDED_IN_CHNROUTE = [
'101.198.198.0/24',
'101.198.199.0/24',
'211.99.96.0/19', // wy.com.cn
// Aliyun Shenzhen
'120.78.0.0/16',
'40.72.0.0/15', // AS58593, Azure China, Shanghai
'42.159.0.0/16', // AS58593, Azure China, Shanghai
'52.130.0.0/17', // AS58593, Azure China, Shanghai
'52.131.0.0/16', // AS58593, Azure China, Beijing
'103.9.8.0/22', // AS58593, Azure China, Backbone
'139.217.0.0/16', // AS58593, Azure China, Shanghai
'139.219.0.0/16', // AS58593, Azure China, Shanghai
'143.64.0.0/16', // AS58593, Azure China, Beijing
'159.27.0.0/16', // AS58593, Azure China, Beijing
'163.228.0.0/16', // AS58593, Azure China, Beijing
// wy.com.cn
'211.99.96.0/19',
// AS58593, Azure China
'40.72.0.0/15', // Shanghai
'42.159.0.0/16', // Shanghai
'52.130.0.0/17', // Shanghai
'52.131.0.0/16', // Beijing
'103.9.8.0/22', // Backbone
'139.217.0.0/16', // Shanghai
'139.219.0.0/16', // Shanghai
'143.64.0.0/16', // Beijing
'159.27.0.0/16', // Beijing
'163.228.0.0/16', // Beijing
// NetEase
'223.252.194.0/24',
'223.252.196.0/24'
];