mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Feat: improve domain alive checking by logging whois
This commit is contained in:
parent
0b3f20f4b7
commit
d9c42ee350
@ -1,13 +1,13 @@
|
|||||||
import { describe, it } from 'mocha';
|
import { describe, it } from 'mocha';
|
||||||
|
|
||||||
import { isDomainAlive, whoisExists } from './is-domain-alive';
|
import { isDomainAlive, noWhois } from './is-domain-alive';
|
||||||
import { expect } from 'expect';
|
import { expect } from 'expect';
|
||||||
|
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
|
|
||||||
describe('whoisExists', () => {
|
describe('whoisExists', () => {
|
||||||
it('.cryptocrawler.io', () => {
|
it('.cryptocrawler.io', () => {
|
||||||
expect(whoisExists({
|
expect(noWhois({
|
||||||
'whois.nic.io': {
|
'whois.nic.io': {
|
||||||
'Domain Status': [],
|
'Domain Status': [],
|
||||||
'Name Server': [],
|
'Name Server': [],
|
||||||
@ -18,11 +18,11 @@ describe('whoisExists', () => {
|
|||||||
'Terms of Use: Access to WHOIS'
|
'Terms of Use: Access to WHOIS'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})).toBe(false);
|
})).toBe('Domain not found.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('.tunevideo.ru', () => {
|
it('.tunevideo.ru', () => {
|
||||||
expect(whoisExists({
|
expect(noWhois({
|
||||||
'whois.tcinet.ru': {
|
'whois.tcinet.ru': {
|
||||||
'Domain Status': [],
|
'Domain Status': [],
|
||||||
'Name Server': [],
|
'Name Server': [],
|
||||||
@ -36,25 +36,7 @@ describe('whoisExists', () => {
|
|||||||
'Last updated on 2025-01-05T11:03:01Z'
|
'Last updated on 2025-01-05T11:03:01Z'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})).toBe(false);
|
})).toBe('No entries found for the selected source(s).');
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,8 +75,8 @@ describe('isDomainAlive', function () {
|
|||||||
// expect((await isDomainAlive('.tayfundogdas.me', true))[1]).toEqual(true);
|
// expect((await isDomainAlive('.tayfundogdas.me', true))[1]).toEqual(true);
|
||||||
// });
|
// });
|
||||||
|
|
||||||
it('hamdandates.com', async () => {
|
it('9s6q.cn', async () => {
|
||||||
process.env.DEBUG = 'true';
|
process.env.DEBUG = 'true';
|
||||||
expect((await isDomainAlive('.hamdandates.com', true))[1]).toEqual(false);
|
expect((await isDomainAlive('.9s6q.cn', true))[1]).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -218,12 +218,13 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
|
|||||||
console.log(JSON.stringify(whois, null, 2));
|
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 });
|
console.log(picocolors.gray('[domain alive]'), picocolors.gray('whois found'), { domain: apexDomain });
|
||||||
return onDomainAlive(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);
|
return onDomainDead(apexDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +244,7 @@ const whoisNotFoundKeywordTest = createKeywordFilter([
|
|||||||
// 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
|
||||||
// some servers (like TLD whois servers) might have cached/outdated results
|
// 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
|
// 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;
|
let empty = true;
|
||||||
|
|
||||||
for (const key in whois) {
|
for (const key in whois) {
|
||||||
@ -262,8 +263,12 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key === 'text') {
|
if (key === 'text') {
|
||||||
if (Array.isArray(whois.text) && whois.text.some(value => whoisNotFoundKeywordTest(value.toLowerCase()))) {
|
if (Array.isArray(whois.text)) {
|
||||||
return false;
|
for (const value of whois.text) {
|
||||||
|
if (whoisNotFoundKeywordTest(value.toLowerCase())) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -274,11 +279,19 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof whois[key] === 'object' && !Array.isArray(whois[key]) && !whoisExists(whois[key])) {
|
if (typeof whois[key] === 'object' && !Array.isArray(whois[key])) {
|
||||||
return false;
|
const tmp = noWhois(whois[key]);
|
||||||
|
if (tmp) {
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !empty;
|
if (empty) {
|
||||||
|
return 'whois is empty';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user