Chore: pre-populate WHOIS mapping

This commit is contained in:
SukkaW 2025-08-23 21:14:27 +08:00
parent f8129cffe1
commit b57f8699e9
2 changed files with 55 additions and 33 deletions

View File

@ -1,4 +1,5 @@
import { createDomainAliveChecker, createRegisterableDomainAliveChecker } from 'domain-alive'; import { createDomainAliveChecker, createRegisterableDomainAliveChecker } from 'domain-alive';
import { $$fetch } from './fetch-retry';
const dnsServers = [ const dnsServers = [
'8.8.8.8', '8.8.8.8',
@ -46,17 +47,29 @@ const dnsServers = [
const resultCache = new Map(); const resultCache = new Map();
const registerableDomainResultCache = new Map(); const registerableDomainResultCache = new Map();
export const isRegisterableDomainAlive = createRegisterableDomainAliveChecker({ export async function getMethods() {
dns: { const customWhoisServersMapping = await (await ($$fetch('https://cdn.jsdelivr.net/npm/whois-servers-list@latest/list.json'))).json() as any;
dnsServers
},
registerableDomainResultCache
});
export const isDomainAlive = createDomainAliveChecker({ const isRegisterableDomainAlive = createRegisterableDomainAliveChecker({
dns: { dns: {
dnsServers dnsServers
}, },
registerableDomainResultCache, registerableDomainResultCache,
resultCache whois: {
customWhoisServersMapping
}
}); });
const isDomainAlive = createDomainAliveChecker({
dns: {
dnsServers
},
registerableDomainResultCache,
resultCache,
whois: {
customWhoisServersMapping
}
});
return { isRegisterableDomainAlive, isDomainAlive };
};

View File

@ -1,6 +1,6 @@
import { SOURCE_DIR } from './constants/dir'; import { SOURCE_DIR } from './constants/dir';
import path from 'node:path'; import path from 'node:path';
import { isDomainAlive, isRegisterableDomainAlive } from './lib/is-domain-alive'; import { getMethods } from './lib/is-domain-alive';
import { fdir as Fdir } from 'fdir'; import { fdir as Fdir } from 'fdir';
import runAgainstSourceFile from './lib/run-against-source-file'; import runAgainstSourceFile from './lib/run-against-source-file';
@ -12,7 +12,13 @@ const queue = newQueue(32);
const deadDomains: string[] = []; const deadDomains: string[] = [];
(async () => { (async () => {
const domainSets = await new Fdir() const [
{ isDomainAlive, isRegisterableDomainAlive },
domainSets,
domainRules
] = await Promise.all([
getMethods(),
new Fdir()
.withFullPaths() .withFullPaths()
.filter((filePath, isDirectory) => { .filter((filePath, isDirectory) => {
if (isDirectory) return false; if (isDirectory) return false;
@ -20,8 +26,8 @@ const deadDomains: string[] = [];
return extname === '.txt' || extname === '.conf'; return extname === '.txt' || extname === '.conf';
}) })
.crawl(SOURCE_DIR + path.sep + 'domainset') .crawl(SOURCE_DIR + path.sep + 'domainset')
.withPromise(); .withPromise(),
const domainRules = await new Fdir() new Fdir()
.withFullPaths() .withFullPaths()
.filter((filePath, isDirectory) => { .filter((filePath, isDirectory) => {
if (isDirectory) return false; if (isDirectory) return false;
@ -29,7 +35,8 @@ const deadDomains: string[] = [];
return extname === '.txt' || extname === '.conf'; return extname === '.txt' || extname === '.conf';
}) })
.crawl(SOURCE_DIR + path.sep + 'non_ip') .crawl(SOURCE_DIR + path.sep + 'non_ip')
.withPromise(); .withPromise()
]);
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic); const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
bar.start(0, 0); bar.start(0, 0);
@ -56,7 +63,9 @@ const deadDomains: string[] = [];
bar.increment(); bar.increment();
if (!registerableDomainAlive) { if (!registerableDomainAlive) {
if (registerableDomain) {
deadDomains.push('.' + registerableDomain); deadDomains.push('.' + registerableDomain);
}
} else if (!includeAllSubdomain && alive != null && !alive) { } else if (!includeAllSubdomain && alive != null && !alive) {
deadDomains.push(domain); deadDomains.push(domain);
} }