Chore: improve domai alive check [skip ci]

This commit is contained in:
SukkaW 2025-01-06 21:37:40 +08:00
parent 20aae1c817
commit 0590097b47
2 changed files with 27 additions and 10 deletions

View File

@ -203,15 +203,13 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
return onDomainAlive(apexDomain); return onDomainAlive(apexDomain);
} }
console.log(picocolors.gray('[domain check]'), picocolors.gray('no NS records'), { domain: apexDomain });
let whois; let whois;
try { try {
whois = await getWhois(apexDomain); whois = await getWhois(apexDomain);
} catch (e) { } catch (e) {
console.log(picocolors.red('[domain dead]'), 'whois error', { domain: apexDomain }, e); console.log(picocolors.red('[domain dead]'), 'whois error', { domain: apexDomain }, e);
return onDomainDead(apexDomain); return onDomainAlive(apexDomain);
} }
if (process.env.DEBUG) { if (process.env.DEBUG) {
@ -224,7 +222,7 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
return onDomainAlive(apexDomain); return onDomainAlive(apexDomain);
} }
console.log(picocolors.red('[domain dead]'), 'whois not found', { domain: apexDomain, whoisError }); console.log(picocolors.red('[domain dead]'), 'whois not found', { domain: apexDomain, err: whoisError });
return onDomainDead(apexDomain); return onDomainDead(apexDomain);
} }
@ -241,7 +239,11 @@ const whoisNotFoundKeywordTest = createKeywordFilter([
'no matching record', 'no matching record',
'no information available about domain name', 'no information available about domain name',
'not been registered', 'not been registered',
'no match!!' 'no match!!',
'status: available',
' is free',
'no object found',
'nothing found'
]); ]);
// whois server can redirect, so whoiser might/will get info from multiple whois servers // whois server can redirect, so whoiser might/will get info from multiple whois servers

View File

@ -9,6 +9,13 @@ import { fdir as Fdir } from 'fdir';
const queue = newQueue(32); const queue = newQueue(32);
const deadDomains: string[] = [];
function onDomain(args: [string, boolean]) {
if (!args[1]) {
deadDomains.push(args[0]);
}
}
(async () => { (async () => {
const domainSets = await new Fdir() const domainSets = await new Fdir()
.withFullPaths() .withFullPaths()
@ -24,7 +31,9 @@ const queue = newQueue(32);
...domainRules.map(runAgainstRuleset) ...domainRules.map(runAgainstRuleset)
]); ]);
console.log('done'); console.log();
console.log();
console.log(JSON.stringify(deadDomains));
})(); })();
export async function runAgainstRuleset(filepath: string) { export async function runAgainstRuleset(filepath: string) {
@ -34,7 +43,7 @@ export async function runAgainstRuleset(filepath: string) {
return; return;
} }
const promises: Array<Promise<[string, boolean]>> = []; const promises: Array<Promise<void>> = [];
for await (const l of readFileByLine(filepath)) { for await (const l of readFileByLine(filepath)) {
const line = processLine(l); const line = processLine(l);
@ -43,7 +52,10 @@ export async function runAgainstRuleset(filepath: string) {
switch (type) { switch (type) {
case 'DOMAIN-SUFFIX': case 'DOMAIN-SUFFIX':
case 'DOMAIN': { case 'DOMAIN': {
promises.push(queue.add(() => keyedAsyncMutexWithQueue(domain, () => isDomainAlive(domain, type === 'DOMAIN-SUFFIX')))); promises.push(
queue.add(() => keyedAsyncMutexWithQueue(domain, () => isDomainAlive(domain, type === 'DOMAIN-SUFFIX')))
.then(onDomain)
);
break; break;
} }
// no default // no default
@ -61,12 +73,15 @@ export async function runAgainstDomainset(filepath: string) {
return; return;
} }
const promises: Array<Promise<[string, boolean]>> = []; const promises: Array<Promise<void>> = [];
for await (const l of readFileByLine(filepath)) { for await (const l of readFileByLine(filepath)) {
const line = processLine(l); const line = processLine(l);
if (!line) continue; if (!line) continue;
promises.push(queue.add(() => keyedAsyncMutexWithQueue(line, () => isDomainAlive(line, line[0] === '.')))); promises.push(
queue.add(() => keyedAsyncMutexWithQueue(line, () => isDomainAlive(line, line[0] === '.')))
.then(onDomain)
);
} }
await Promise.all(promises); await Promise.all(promises);