Skip to content

Commit

Permalink
Feat: improve domain alive checking by logging whois
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jan 5, 2025
1 parent b05d0cf commit e1a6f36
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
32 changes: 7 additions & 25 deletions Build/lib/is-domain-alive.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { describe, it } from 'mocha';

import { isDomainAlive, whoisExists } from './is-domain-alive';
import { isDomainAlive, noWhois } from './is-domain-alive';
import { expect } from 'expect';

import process from 'node:process';

describe('whoisExists', () => {
it('.cryptocrawler.io', () => {
expect(whoisExists({
expect(noWhois({
'whois.nic.io': {
'Domain Status': [],
'Name Server': [],
Expand All @@ -18,11 +18,11 @@ describe('whoisExists', () => {
'Terms of Use: Access to WHOIS'
]
}
})).toBe(false);
})).toBe('Domain not found.');
});

it('.tunevideo.ru', () => {
expect(whoisExists({
expect(noWhois({
'whois.tcinet.ru': {
'Domain Status': [],
'Name Server': [],
Expand All @@ -36,25 +36,7 @@ describe('whoisExists', () => {
'Last updated on 2025-01-05T11:03:01Z'
]
}
})).toBe(false);
});

it('.myqloud.com', () => {
expect(whoisExists({
'whois.tcinet.ru': {
'Domain Status': [],
'Name Server': [],
text: [
'% TCI Whois Service. Terms of use:',
'% https://tcinet.ru/documents/whois_ru_rf.pdf (in Russian)',
'% https://tcinet.ru/documents/whois_su.pdf (in Russian)',
'',
'No entries found for the selected source(s).',
'',
'Last updated on 2025-01-05T11:03:01Z'
]
}
})).toBe(false);
})).toBe('No entries found for the selected source(s).');
});
});

Expand Down Expand Up @@ -93,8 +75,8 @@ describe('isDomainAlive', function () {
// expect((await isDomainAlive('.tayfundogdas.me', true))[1]).toEqual(true);
// });

it('hamdandates.com', async () => {
it('9s6q.cn', async () => {
process.env.DEBUG = 'true';
expect((await isDomainAlive('.hamdandates.com', true))[1]).toEqual(false);
expect((await isDomainAlive('.9s6q.cn', true))[1]).toEqual(false);
});
});
29 changes: 21 additions & 8 deletions Build/lib/is-domain-alive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,13 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
console.log(JSON.stringify(whois, null, 2));
}

if (whoisExists(whois)) {
const whoisError = noWhois(whois);
if (!whoisError) {
console.log(picocolors.gray('[domain alive]'), picocolors.gray('whois found'), { domain: apexDomain });
return onDomainAlive(apexDomain);
}

console.log(picocolors.red('[domain dead]'), 'whois not found', { domain: apexDomain });
console.log(picocolors.red('[domain dead]'), 'whois not found', { domain: apexDomain, whoisError });
return onDomainDead(apexDomain);
}

Expand All @@ -243,7 +244,7 @@ const whoisNotFoundKeywordTest = createKeywordFilter([
// whois server can redirect, so whoiser might/will get info from multiple whois servers
// some servers (like TLD whois servers) might have cached/outdated results
// we can only make sure a domain is alive once all response from all whois servers demonstrate so
export function whoisExists(whois: whoiser.WhoisSearchResult) {
export function noWhois(whois: whoiser.WhoisSearchResult): null | string {
let empty = true;

for (const key in whois) {
Expand All @@ -262,8 +263,12 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
}

if (key === 'text') {
if (Array.isArray(whois.text) && whois.text.some(value => whoisNotFoundKeywordTest(value.toLowerCase()))) {
return false;
if (Array.isArray(whois.text)) {
for (const value of whois.text) {
if (whoisNotFoundKeywordTest(value.toLowerCase())) {
return value;
}
}
}
continue;
}
Expand All @@ -274,11 +279,19 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
continue;
}

if (typeof whois[key] === 'object' && !Array.isArray(whois[key]) && !whoisExists(whois[key])) {
return false;
if (typeof whois[key] === 'object' && !Array.isArray(whois[key])) {
const tmp = noWhois(whois[key]);
if (tmp) {
return tmp;
}
continue;
}
}
}

return !empty;
if (empty) {
return 'whois is empty';
}

return null;
}

0 comments on commit e1a6f36

Please sign in to comment.