From d5f755e09e058f009c9a671dad0a2aa8df0e7cd4 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sat, 4 Feb 2023 12:15:50 +0200 Subject: [PATCH] fixed - query TLD whois from more sources --- CHANGELOG.md | 2 ++ src/whoiser.js | 14 ++++++-------- test/tlds.js | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d99c98..9407a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ #### 1.15.0 - 4 February 2023 - Updated - Merge/normalize more WHOIS domain labels +- Fixed - Query more sources for TLD whois server [#86](https://github.com/LayeredStudio/whoiser/pull/86) + #### 1.14.0 - 14 January 2023 - Added - Support for third level domains [#80](https://github.com/LayeredStudio/whoiser/pull/80) diff --git a/src/whoiser.js b/src/whoiser.js index 97f335d..2040adb 100644 --- a/src/whoiser.js +++ b/src/whoiser.js @@ -91,23 +91,22 @@ const whoisTld = async (query, { timeout = 15000, raw = false, domainTld = '' } data.__raw = result } - // query for WHOIS server in more sources + // if no whois server found, search in more sources if (!data.whois) { //todo - // split `query` in domain parts and request info for all tld combinations - // ex: query="example.com.tld" make 3 requests for "example.com.tld" "com.tld" "tld" + // instead of using `domainTld`, split `query` in domain parts and request info for all tld combinations + // example: query="example.com.tld" make 3 requests for "example.com.tld" / "com.tld" / "tld" - const whois = await whoisTldAlternate(domainTld) + const whois = await whoisTldAlternate(domainTld || query) if (whois) { data.whois = whois data.domain = data.domain || whois - data.refer = data.refer || whois } } - if (!data.domain || !data.whois) { + if (!data.domain && !data.whois) { throw new Error(`TLD "${query}" not found`) } @@ -145,8 +144,7 @@ const whoisDomain = async (rawDomain, { host = null, timeout = 15000, follow = 2 // hardcoded WHOIS queries.. if (host === 'whois.denic.de') { query = `-T dn ${rawDomain}` - } - if (host === 'whois.jprs.jp') { + } else if (host === 'whois.jprs.jp') { query = `${query}/e` } diff --git a/test/tlds.js b/test/tlds.js index 0348402..615f030 100644 --- a/test/tlds.js +++ b/test/tlds.js @@ -35,6 +35,7 @@ describe('#whoiser.tld()', function() { it('should return WHOIS for "analytics" (no whois server)', async function() { let whois = await whoiser.tld('analytics') + assert.equal(whois.whois, 'whois.nic.analytics', 'WHOIS server doesn\'t match') assert.equal(whois.domain, 'ANALYTICS', 'TLD doesn\'t match') assert.equal(whois.created, '2015-11-20', 'Created date doesn\'t match') });