Skip to content

Commit ffda1ab

Browse files
committed
Chore: improve domai alive check [skip ci]
1 parent 20aae1c commit ffda1ab

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

Build/lib/is-domain-alive.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,13 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
203203
return onDomainAlive(apexDomain);
204204
}
205205

206-
console.log(picocolors.gray('[domain check]'), picocolors.gray('no NS records'), { domain: apexDomain });
207-
208206
let whois;
209207

210208
try {
211209
whois = await getWhois(apexDomain);
212210
} catch (e) {
213211
console.log(picocolors.red('[domain dead]'), 'whois error', { domain: apexDomain }, e);
214-
return onDomainDead(apexDomain);
212+
return onDomainAlive(apexDomain);
215213
}
216214

217215
if (process.env.DEBUG) {
@@ -224,7 +222,7 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
224222
return onDomainAlive(apexDomain);
225223
}
226224

227-
console.log(picocolors.red('[domain dead]'), 'whois not found', { domain: apexDomain, whoisError });
225+
console.log(picocolors.red('[domain dead]'), 'whois not found', { domain: apexDomain, err: whoisError });
228226
return onDomainDead(apexDomain);
229227
}
230228

@@ -241,7 +239,8 @@ const whoisNotFoundKeywordTest = createKeywordFilter([
241239
'no matching record',
242240
'no information available about domain name',
243241
'not been registered',
244-
'no match!!'
242+
'no match!!',
243+
'status: available'
245244
]);
246245

247246
// whois server can redirect, so whoiser might/will get info from multiple whois servers

Build/validate-domain-alive.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import { fdir as Fdir } from 'fdir';
99

1010
const queue = newQueue(32);
1111

12+
const deadDomains: string[] = [];
13+
function onDomain(args: [string, boolean]) {
14+
if (!args[1]) {
15+
deadDomains.push(args[0]);
16+
}
17+
}
18+
1219
(async () => {
1320
const domainSets = await new Fdir()
1421
.withFullPaths()
@@ -24,7 +31,9 @@ const queue = newQueue(32);
2431
...domainRules.map(runAgainstRuleset)
2532
]);
2633

27-
console.log('done');
34+
console.log();
35+
console.log();
36+
console.log(JSON.stringify(deadDomains));
2837
})();
2938

3039
export async function runAgainstRuleset(filepath: string) {
@@ -34,7 +43,7 @@ export async function runAgainstRuleset(filepath: string) {
3443
return;
3544
}
3645

37-
const promises: Array<Promise<[string, boolean]>> = [];
46+
const promises: Array<Promise<void>> = [];
3847

3948
for await (const l of readFileByLine(filepath)) {
4049
const line = processLine(l);
@@ -43,7 +52,10 @@ export async function runAgainstRuleset(filepath: string) {
4352
switch (type) {
4453
case 'DOMAIN-SUFFIX':
4554
case 'DOMAIN': {
46-
promises.push(queue.add(() => keyedAsyncMutexWithQueue(domain, () => isDomainAlive(domain, type === 'DOMAIN-SUFFIX'))));
55+
promises.push(
56+
queue.add(() => keyedAsyncMutexWithQueue(domain, () => isDomainAlive(domain, type === 'DOMAIN-SUFFIX')))
57+
.then(onDomain)
58+
);
4759
break;
4860
}
4961
// no default
@@ -61,12 +73,15 @@ export async function runAgainstDomainset(filepath: string) {
6173
return;
6274
}
6375

64-
const promises: Array<Promise<[string, boolean]>> = [];
76+
const promises: Array<Promise<void>> = [];
6577

6678
for await (const l of readFileByLine(filepath)) {
6779
const line = processLine(l);
6880
if (!line) continue;
69-
promises.push(queue.add(() => keyedAsyncMutexWithQueue(line, () => isDomainAlive(line, line[0] === '.'))));
81+
promises.push(
82+
queue.add(() => keyedAsyncMutexWithQueue(line, () => isDomainAlive(line, line[0] === '.')))
83+
.then(onDomain)
84+
);
7085
}
7186

7287
await Promise.all(promises);

0 commit comments

Comments
 (0)