1
mirror of https://github.com/jakejarvis/rdapper.git synced 2025-10-18 20:14:27 -04:00

Update exports in index.ts to include .js extensions, add centralized WHOIS server fallbacks for TLDs in whois-fallbacks.ts, and integrate fallbacks into the ianaWhoisServerForTld function in whois.ts for improved error handling.

This commit is contained in:
2025-09-24 16:53:12 -04:00
parent a788b0147a
commit 43fa2a12c7
3 changed files with 94 additions and 4 deletions

View File

@@ -1,2 +1,2 @@
export * from "./lookup";
export * from "./types";
export * from "./lookup.js";
// export * from "./types.js";

84
src/whois-fallbacks.ts Normal file
View File

@@ -0,0 +1,84 @@
// Centralized WHOIS server fallbacks by TLD.
// These are used when IANA's TLD page does not list a server or is unreachable.
export const WHOIS_FALLBACKS: Record<string, string> = {
// gTLDs
com: "whois.verisign-grs.com",
net: "whois.verisign-grs.com",
org: "whois.pir.org",
info: "whois.afilias.net",
biz: "whois.nic.biz",
xyz: "whois.nic.xyz",
top: "whois.nic.top",
club: "whois.nic.club",
site: "whois.nic.site",
online: "whois.nic.online",
shop: "whois.nic.shop",
store: "whois.nic.store",
tech: "whois.nic.tech",
space: "whois.nic.space",
link: "whois.nic.link",
guru: "whois.nic.guru",
mobi: "whois.nic.mobi",
name: "whois.nic.name",
pro: "whois.nic.pro",
tel: "whois.nic.tel",
travel: "whois.nic.travel",
aero: "whois.aero",
jobs: "whois.nic.jobs",
cat: "whois.nic.cat",
museum: "whois.museum",
coop: "whois.nic.coop",
asia: "whois.nic.asia",
app: "whois.nic.google",
dev: "whois.nic.google",
page: "whois.nic.google",
blog: "whois.nic.blog",
// ccTLDs (port 43 policy varies by registry)
us: "whois.nic.us",
uk: "whois.nic.uk",
co: "whois.nic.co",
me: "whois.nic.me",
tv: "whois.nic.tv",
io: "whois.nic.io",
ai: "whois.nic.ai",
de: "whois.denic.de",
fr: "whois.nic.fr",
nl: "whois.domain-registry.nl",
ru: "whois.tcinet.ru",
pl: "whois.dns.pl",
br: "whois.registro.br",
it: "whois.nic.it",
es: "whois.nic.es",
se: "whois.iis.se",
no: "whois.norid.no",
dk: "whois.dk-hostmaster.dk",
fi: "whois.fi",
ch: "whois.nic.ch",
at: "whois.nic.at",
be: "whois.dns.be",
cz: "whois.nic.cz",
sk: "whois.sk-nic.sk",
hu: "whois.nic.hu",
ro: "whois.rotld.ro",
bg: "whois.register.bg",
gr: "whois.ics.forth.gr",
tr: "whois.trabis.gov.tr",
il: "whois.isoc.org.il",
za: "whois.registry.net.za",
nz: "whois.srs.net.nz",
jp: "whois.jprs.jp",
cn: "whois.cnnic.cn",
kr: "whois.kr",
tw: "whois.twnic.net.tw",
sg: "whois.sgnic.sg",
hk: "whois.hkirc.hk",
id: "whois.id",
my: "whois.mynic.my",
ph: "whois.dot.ph",
th: "whois.thnic.co.th",
vn: "whois.vnnic.vn",
mx: "whois.mx",
ar: "whois.nic.ar",
cl: "whois.nic.cl",
pe: "kero.yachay.pe",
};

View File

@@ -2,6 +2,7 @@ import { createConnection } from "node:net";
import { DEFAULT_TIMEOUT_MS } from "./config.js";
import type { LookupOptions } from "./types.js";
import { withTimeout } from "./utils.js";
import { WHOIS_FALLBACKS } from "./whois-fallbacks.js";
export interface WhoisQueryResult {
serverQueried: string;
@@ -84,10 +85,15 @@ export async function ianaWhoisServerForTld(
html.match(/Whois Server:\s*<a[^>]*>([^<]+)<\/a>/i) ||
html.match(/Whois Server:\s*([^<\n]+)/i);
const server = m?.[1]?.trim();
if (!server) return undefined;
if (!server)
return (
WHOIS_FALLBACKS[tld.toLowerCase()] ?? `whois.nic.${tld.toLowerCase()}`
);
return server.replace(/^https?:\/\//i, "").replace(/\/$/, "");
} catch {
return undefined;
return (
WHOIS_FALLBACKS[tld.toLowerCase()] ?? `whois.nic.${tld.toLowerCase()}`
);
}
}