Skip to content

Commit

Permalink
Refactor: enable more DNS to validate alive domains
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 13, 2024
1 parent 76f5a72 commit c16931e
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions Build/validate-domain-alive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const dohServers: Array<[string, DNS2.DnsResolver]> = ([
// 'zero.dns0.eu',
'dns.nextdns.io',
'anycast.dns.nextdns.io',
// 'wikimedia-dns.org',
'wikimedia-dns.org',
// 'ordns.he.net',
// 'dns.mullvad.net',
'basic.rethinkdns.com'
Expand Down Expand Up @@ -181,22 +181,39 @@ export async function isDomainAlive(domain: string, isSuffix: boolean): Promise<
return [domain, false] as const;
}

const $domain = domain[0] === '.' ? domain.slice(1) : domain;

if (!isSuffix) {
const $domain = domain[0] === '.' ? domain.slice(1) : domain;
const aDns: string[] = [];
const aaaaDns: string[] = [];

// test 2 times before make sure record is empty
for (let i = 0; i < 2; i++) {
// eslint-disable-next-line no-await-in-loop -- sequential
const aRecords = (await resolve($domain, 'A'));
if (aRecords.answers.length !== 0) {
domainAliveMap.set(domain, true);
return [domain, true] as const;
}

const aRecords = (await resolve($domain, 'A'));
if (aRecords.answers.length === 0) {
aDns.push(aRecords.dns);
}
for (let i = 0; i < 2; i++) {
// eslint-disable-next-line no-await-in-loop -- sequential
const aaaaRecords = (await resolve($domain, 'AAAA'));
if (aaaaRecords.answers.length === 0) {
console.log(picocolors.red('[domain dead]'), 'no A/AAAA records', { domain, a: aRecords.dns, aaaa: aaaaRecords.dns });
domainAliveMap.set($domain, false);
return [domain, false] as const;
if (aaaaRecords.answers.length !== 0) {
domainAliveMap.set(domain, true);
return [domain, true] as const;
}

aaaaDns.push(aaaaRecords.dns);
}

console.log(picocolors.red('[domain dead]'), 'no A/AAAA records', { domain, a: aDns, aaaa: aaaaDns });
}

domainAliveMap.set(domain, true);
return [domain, true] as const;
domainAliveMap.set($domain, false);
return [domain, false] as const;
}

export async function runAgainstRuleset(filepath: string) {
Expand Down

0 comments on commit c16931e

Please sign in to comment.