Skip to content

Commit

Permalink
Improve Domain Alive Check
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 8, 2024
1 parent 1a1513c commit 73f0321
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Build/validate-domain-alive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const dohServers: Array<[string, DNS2.DnsResolver]> = ([
'wikimedia-dns.org',
// 'ordns.he.net',
'dns.mullvad.net',
'zero.dns0.eu',
// 'zero.dns0.eu',
'basic.rethinkdns.com'
// 'ada.openbld.net',
// 'dns.rabbitdns.org'
Expand All @@ -48,7 +48,7 @@ const dohServers: Array<[string, DNS2.DnsResolver]> = ([
})
] as const);

const queue = newQueue(24);
const queue = newQueue(18);
const mutex = new Map<string, Promise<unknown>>();
function keyedAsyncMutexWithQueue<T>(key: string, fn: () => Promise<T>) {
if (mutex.has(key)) {
Expand Down Expand Up @@ -91,6 +91,10 @@ const resolve: DNS2.DnsResolver<DnsResponse> = async (...args) => {
}
};

async function getWhois(domain: string) {
return asyncRetry(() => whoiser.domain(domain), { retries: 5 });
}

(async () => {
const domainSets = await new Fdir()
.withFullPaths()
Expand Down Expand Up @@ -130,7 +134,7 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
let whois;

try {
whois = await whoiser.domain(apexDomain);
whois = await getWhois(apexDomain);
} catch (e) {
console.log('[whois fail]', 'whois error', { domain: apexDomain }, e);
return [apexDomain, true];
Expand Down Expand Up @@ -238,7 +242,7 @@ export async function runAgainstDomainset(filepath: string) {
for await (const l of readFileByLine(filepath)) {
const line = processLine(l);
if (!line) continue;
promises.push(isDomainAlive(line, line[0] === '.'));
promises.push(keyedAsyncMutexWithQueue(line, () => isDomainAlive(line, line[0] === '.')));
}

await Promise.all(promises);
Expand Down

0 comments on commit 73f0321

Please sign in to comment.