|
@@ -8,6 +8,7 @@ import { $$fetch } from './lib/fetch-retry';
|
|
|
import { fastIpVersion } from 'foxts/fast-ip-version';
|
|
import { fastIpVersion } from 'foxts/fast-ip-version';
|
|
|
import DNS2 from 'dns2';
|
|
import DNS2 from 'dns2';
|
|
|
import { getTelegramBackupIPFromBase64 } from './lib/get-telegram-backup-ip';
|
|
import { getTelegramBackupIPFromBase64 } from './lib/get-telegram-backup-ip';
|
|
|
|
|
+import picocolors from 'picocolors';
|
|
|
|
|
|
|
|
export const getTelegramCIDRPromise = once(async () => {
|
|
export const getTelegramCIDRPromise = once(async () => {
|
|
|
const resp = await $$fetch('https://core.telegram.org/resources/cidr.txt');
|
|
const resp = await $$fetch('https://core.telegram.org/resources/cidr.txt');
|
|
@@ -43,33 +44,45 @@ export const getTelegramCIDRPromise = once(async () => {
|
|
|
dns: '1.0.0.1',
|
|
dns: '1.0.0.1',
|
|
|
http: false
|
|
http: false
|
|
|
})
|
|
})
|
|
|
- ].map(async (client) => {
|
|
|
|
|
- try {
|
|
|
|
|
- // tapv3.stel.com was for testing server
|
|
|
|
|
- const resp = await client('apv3.stel.com', 'TXT');
|
|
|
|
|
- const strings = resp.answers.map(i => i.data);
|
|
|
|
|
-
|
|
|
|
|
- const str = strings[0]!.length > strings[1]!.length
|
|
|
|
|
- ? strings[0]! + strings[1]!
|
|
|
|
|
- : strings[1]! + strings[0]!;
|
|
|
|
|
-
|
|
|
|
|
- const ips = getTelegramBackupIPFromBase64(str);
|
|
|
|
|
- ips.forEach(i => i && backupIPs.add(i.ip));
|
|
|
|
|
- } catch {}
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ ].flatMap(
|
|
|
|
|
+ (client) => [
|
|
|
|
|
+ 'apv3.stel.com', // prod
|
|
|
|
|
+ 'tapv3.stel.com' // test
|
|
|
|
|
+ ].map(async (domain) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // tapv3.stel.com was for testing server
|
|
|
|
|
+ const resp = await client(domain, 'TXT');
|
|
|
|
|
+ const strings = resp.answers.map(i => i.data);
|
|
|
|
|
+
|
|
|
|
|
+ const str = strings[0]!.length > strings[1]!.length
|
|
|
|
|
+ ? strings[0]! + strings[1]!
|
|
|
|
|
+ : strings[1]! + strings[0]!;
|
|
|
|
|
+
|
|
|
|
|
+ const ips = getTelegramBackupIPFromBase64(str);
|
|
|
|
|
+ ips.forEach(i => backupIPs.add(i.ip));
|
|
|
|
|
+
|
|
|
|
|
+ console.log('[telegram backup ip]', picocolors.green('DoH TXT'), { domain, ips });
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('[telegram backup ip]', picocolors.red('DoH TXT error'), { domain }, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ ));
|
|
|
|
|
|
|
|
- // Backup IP Source 2: Firebase Realtime Database
|
|
|
|
|
|
|
+ // Backup IP Source 2: Firebase Realtime Database (test server not supported)
|
|
|
try {
|
|
try {
|
|
|
const text = await (await $$fetch('https://reserve-5a846.firebaseio.com/ipconfigv3.json')).json();
|
|
const text = await (await $$fetch('https://reserve-5a846.firebaseio.com/ipconfigv3.json')).json();
|
|
|
if (typeof text === 'string' && text.length === 344) {
|
|
if (typeof text === 'string' && text.length === 344) {
|
|
|
const ips = getTelegramBackupIPFromBase64(text);
|
|
const ips = getTelegramBackupIPFromBase64(text);
|
|
|
- ips.forEach(i => i && backupIPs.add(i.ip));
|
|
|
|
|
|
|
+ ips.forEach(i => backupIPs.add(i.ip));
|
|
|
|
|
+
|
|
|
|
|
+ console.log('[telegram backup ip]', picocolors.green('Firebase Realtime DB'), { ips });
|
|
|
}
|
|
}
|
|
|
- } catch {
|
|
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('[telegram backup ip]', picocolors.red('Firebase Realtime DB error'), e);
|
|
|
// ignore all errors
|
|
// ignore all errors
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Backup IP Source 3: Firebase Value Store
|
|
|
|
|
|
|
+ // Backup IP Source 3: Firebase Value Store (test server not supported)
|
|
|
try {
|
|
try {
|
|
|
const json = await (await $$fetch('https://firestore.googleapis.com/v1/projects/reserve-5a846/databases/(default)/documents/ipconfig/v3')).json();
|
|
const json = await (await $$fetch('https://firestore.googleapis.com/v1/projects/reserve-5a846/databases/(default)/documents/ipconfig/v3')).json();
|
|
|
if (
|
|
if (
|
|
@@ -79,22 +92,37 @@ export const getTelegramCIDRPromise = once(async () => {
|
|
|
&& 'stringValue' in json.fields.data && typeof json.fields.data.stringValue === 'string' && json.fields.data.stringValue.length === 344
|
|
&& 'stringValue' in json.fields.data && typeof json.fields.data.stringValue === 'string' && json.fields.data.stringValue.length === 344
|
|
|
) {
|
|
) {
|
|
|
const ips = getTelegramBackupIPFromBase64(json.fields.data.stringValue);
|
|
const ips = getTelegramBackupIPFromBase64(json.fields.data.stringValue);
|
|
|
- ips.forEach(i => i && backupIPs.add(i.ip));
|
|
|
|
|
|
|
+ ips.forEach(i => backupIPs.add(i.ip));
|
|
|
|
|
+
|
|
|
|
|
+ console.log('[telegram backup ip]', picocolors.green('Firebase Value Store'), { ips });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.error('[telegram backup ip]', picocolors.red('Firebase Value Store data format invalid'), { json });
|
|
|
}
|
|
}
|
|
|
- } catch {}
|
|
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('[telegram backup ip]', picocolors.red('Firebase Value Store error'), e);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Backup IP Source 4: Google App Engine: https://dns-telegram.appspot.com https://dns-telegram.appspot.com/test
|
|
|
|
|
- try {
|
|
|
|
|
- const text = await (await $$fetch('https://dns-telegram.appspot.com')).text();
|
|
|
|
|
- if (text.length === 344) {
|
|
|
|
|
- const ips = getTelegramBackupIPFromBase64(text);
|
|
|
|
|
- ips.forEach(i => i && backupIPs.add(i.ip));
|
|
|
|
|
|
|
+ // Backup IP Source 4: Google App Engine
|
|
|
|
|
+ await Promise.all([
|
|
|
|
|
+ 'https://dns-telegram.appspot.com',
|
|
|
|
|
+ 'https://dns-telegram.appspot.com/test'
|
|
|
|
|
+ ].map(async (url) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const text = await (await $$fetch(url)).text();
|
|
|
|
|
+ if (text.length === 344) {
|
|
|
|
|
+ const ips = getTelegramBackupIPFromBase64(text);
|
|
|
|
|
+ ips.forEach(i => backupIPs.add(i.ip));
|
|
|
|
|
+
|
|
|
|
|
+ console.log('[telegram backup ip]', picocolors.green('Google App Engine'), { url, ips });
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('[telegram backup ip]', picocolors.red('Google App Engine error'), { url }, e);
|
|
|
}
|
|
}
|
|
|
- } catch {}
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
// tcdnb.azureedge.net no longer works
|
|
// tcdnb.azureedge.net no longer works
|
|
|
|
|
|
|
|
- console.log(`Found ${backupIPs.size} backup IPs:`, backupIPs);
|
|
|
|
|
|
|
+ console.log('[telegram backup ip]', `Found ${backupIPs.size} backup IPs:`, backupIPs);
|
|
|
|
|
|
|
|
ipcidr.push(...Array.from(backupIPs).map(i => i + '/32'));
|
|
ipcidr.push(...Array.from(backupIPs).map(i => i + '/32'));
|
|
|
|
|
|