mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Feat: improve domain alive checking
This commit is contained in:
parent
57b5d2933f
commit
0b3f20f4b7
@ -3,6 +3,8 @@ import { describe, it } from 'mocha';
|
||||
import { isDomainAlive, whoisExists } from './is-domain-alive';
|
||||
import { expect } from 'expect';
|
||||
|
||||
import process from 'node:process';
|
||||
|
||||
describe('whoisExists', () => {
|
||||
it('.cryptocrawler.io', () => {
|
||||
expect(whoisExists({
|
||||
@ -59,19 +61,40 @@ describe('whoisExists', () => {
|
||||
describe('isDomainAlive', function () {
|
||||
this.timeout(10000);
|
||||
|
||||
it('.cryptocrawler.io', async () => {
|
||||
expect((await isDomainAlive('.cryptocrawler.io', true))[1]).toEqual(false);
|
||||
});
|
||||
// it('.cryptocrawler.io', async () => {
|
||||
// expect((await isDomainAlive('.cryptocrawler.io', true))[1]).toEqual(false);
|
||||
// });
|
||||
|
||||
it('.tunevideo.ru', async () => {
|
||||
expect((await isDomainAlive('.tunevideo.ru', true))[1]).toEqual(false);
|
||||
});
|
||||
// it('.tunevideo.ru', async () => {
|
||||
// expect((await isDomainAlive('.tunevideo.ru', true))[1]).toEqual(false);
|
||||
// });
|
||||
|
||||
it('.myqloud.com', async () => {
|
||||
expect((await isDomainAlive('.myqloud.com', true))[1]).toEqual(true);
|
||||
});
|
||||
// it('.myqloud.com', async () => {
|
||||
// expect((await isDomainAlive('.myqloud.com', true))[1]).toEqual(true);
|
||||
// });
|
||||
|
||||
it('discount-deal.org', async () => {
|
||||
expect((await isDomainAlive('discount-deal.org', false))[1]).toEqual(false);
|
||||
// it('discount-deal.org', async () => {
|
||||
// expect((await isDomainAlive('discount-deal.org', false))[1]).toEqual(false);
|
||||
// });
|
||||
|
||||
// it('ithome.com.tw', async () => {
|
||||
// expect((await isDomainAlive('ithome.com.tw', false))[1]).toEqual(true);
|
||||
// });
|
||||
|
||||
// it('flipkart.com', async () => {
|
||||
// expect((await isDomainAlive('flipkart.com', false))[1]).toEqual(true);
|
||||
// });
|
||||
|
||||
// it('lzzyimg.com', async () => {
|
||||
// expect((await isDomainAlive('.lzzyimg.com', true))[1]).toEqual(true);
|
||||
// });
|
||||
|
||||
// it('tayfundogdas.me', async () => {
|
||||
// expect((await isDomainAlive('.tayfundogdas.me', true))[1]).toEqual(true);
|
||||
// });
|
||||
|
||||
it('hamdandates.com', async () => {
|
||||
process.env.DEBUG = 'true';
|
||||
expect((await isDomainAlive('.hamdandates.com', true))[1]).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,6 +8,8 @@ import * as whoiser from 'whoiser';
|
||||
|
||||
import { createRetrieKeywordFilter as createKeywordFilter } from 'foxts/retrie';
|
||||
|
||||
import process from 'node:process';
|
||||
|
||||
const mutex = new Map<string, Promise<unknown>>();
|
||||
export function keyedAsyncMutexWithQueue<T>(key: string, fn: () => Promise<T>) {
|
||||
if (mutex.has(key)) {
|
||||
@ -201,6 +203,8 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
|
||||
return onDomainAlive(apexDomain);
|
||||
}
|
||||
|
||||
console.log(picocolors.gray('[domain check]'), picocolors.gray('no NS records'), { domain: apexDomain });
|
||||
|
||||
let whois;
|
||||
|
||||
try {
|
||||
@ -210,10 +214,12 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
|
||||
return onDomainDead(apexDomain);
|
||||
}
|
||||
|
||||
// console.log(JSON.stringify(whois, null, 2));
|
||||
if (process.env.DEBUG) {
|
||||
console.log(JSON.stringify(whois, null, 2));
|
||||
}
|
||||
|
||||
if (whoisExists(whois)) {
|
||||
console.log(picocolors.gray('[domain alive]'), 'whois found', { domain: apexDomain });
|
||||
console.log(picocolors.gray('[domain alive]'), picocolors.gray('whois found'), { domain: apexDomain });
|
||||
return onDomainAlive(apexDomain);
|
||||
}
|
||||
|
||||
@ -229,9 +235,14 @@ const whoisNotFoundKeywordTest = createKeywordFilter([
|
||||
'no entries',
|
||||
'no data found',
|
||||
'is available for registration',
|
||||
'currently available for application'
|
||||
'currently available for application',
|
||||
'no matching record',
|
||||
'no information available about domain name'
|
||||
]);
|
||||
|
||||
// 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) {
|
||||
let empty = true;
|
||||
|
||||
@ -240,13 +251,13 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
|
||||
empty = false;
|
||||
|
||||
if (key === 'error') {
|
||||
if (
|
||||
(typeof whois.error === 'string' && whois.error)
|
||||
|| (Array.isArray(whois.error) && whois.error.length > 0)
|
||||
) {
|
||||
console.error(whois);
|
||||
return true;
|
||||
}
|
||||
// if (
|
||||
// (typeof whois.error === 'string' && whois.error)
|
||||
// || (Array.isArray(whois.error) && whois.error.length > 0)
|
||||
// ) {
|
||||
// console.error(whois);
|
||||
// return true;
|
||||
// }
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -257,9 +268,9 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
|
||||
continue;
|
||||
}
|
||||
if (key === 'Name Server') {
|
||||
if (Array.isArray(whois[key]) && whois[key].length === 0) {
|
||||
return false;
|
||||
}
|
||||
// if (Array.isArray(whois[key]) && whois[key].length === 0) {
|
||||
// return false;
|
||||
// }
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -268,5 +279,6 @@ export function whoisExists(whois: whoiser.WhoisSearchResult) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !empty;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user