Add CLI script for domain lookup and create package-lock.json; update README and package.json for clarity and dependencies

This commit is contained in:
2025-09-24 17:28:12 -04:00
parent 43fa2a12c7
commit 0a852ff3cd
8 changed files with 315 additions and 238 deletions
+15
View File
@@ -1,3 +1,5 @@
import psl from "psl";
// Lightweight date parsing helpers to avoid external dependencies.
// We aim to parse common RDAP and WHOIS date representations and return a UTC ISO string.
export function toISO(
@@ -189,6 +191,19 @@ export function sleep(ms: number): Promise<void> {
export function extractTld(domain: string): string {
const lower = domain.trim().toLowerCase();
try {
const parsed = psl.parse?.(lower);
if (!("tld" in parsed)) {
return lower;
}
const suffix = parsed?.tld;
if (suffix) {
const labels = String(suffix).split(".").filter(Boolean);
if (labels.length) return labels[labels.length - 1];
}
} catch {
// ignore and fall back
}
const parts = lower.split(".").filter(Boolean);
return parts[parts.length - 1] ?? lower;
}
-84
View File
@@ -1,84 +0,0 @@
// 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",
};
+7 -7
View File
@@ -2,7 +2,6 @@ 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;
@@ -73,6 +72,11 @@ export async function ianaWhoisServerForTld(
tld: string,
options?: LookupOptions,
): Promise<string | undefined> {
const EXCEPTIONS: Record<string, string> = {
com: "whois.verisign-grs.com",
net: "whois.verisign-grs.com",
org: "whois.pir.org",
};
const url = `https://www.iana.org/domains/root/db/${encodeURIComponent(tld)}.html`;
try {
const res = await withTimeout(
@@ -86,14 +90,10 @@ export async function ianaWhoisServerForTld(
html.match(/Whois Server:\s*([^<\n]+)/i);
const server = m?.[1]?.trim();
if (!server)
return (
WHOIS_FALLBACKS[tld.toLowerCase()] ?? `whois.nic.${tld.toLowerCase()}`
);
return EXCEPTIONS[tld.toLowerCase()] ?? `whois.nic.${tld.toLowerCase()}`;
return server.replace(/^https?:\/\//i, "").replace(/\/$/, "");
} catch {
return (
WHOIS_FALLBACKS[tld.toLowerCase()] ?? `whois.nic.${tld.toLowerCase()}`
);
return EXCEPTIONS[tld.toLowerCase()] ?? `whois.nic.${tld.toLowerCase()}`;
}
}