Skip to content

Full Toolkit for Next-Level Domain Analysis

Improve WhoisQuickInfo resilience 💪

Felix Wotschofsky4699c0c46742
diff --git a/components/WhoisQuickInfo.tsx b/components/WhoisQuickInfo.tsx
index a6a2f91..2b70d5f 100644
--- a/components/WhoisQuickInfo.tsx
+++ b/components/WhoisQuickInfo.tsx
@@ -1,3 +1,4 @@
+import isValidDomain from 'is-valid-domain';
import { FC } from 'react';
import whoiser, { type WhoisSearchResult } from 'whoiser';
@@ -7,42 +8,68 @@ type WhoisQuickInfoProps = {
domain: string;
};
+const getSummary = async (
+ domain: string
+): Promise<{ registrar: string; createdAt: string; dnssec: string }> => {
+ // TODO Allow resolving for TLDs
+ if (!isValidDomain(domain)) {
+ return {
+ registrar: 'Unavailable',
+ createdAt: 'Unavailable',
+ dnssec: 'Unavailable',
+ };
+ }
+
+ try {
+ const results = await whoiser(domain, {
+ timeout: 5000,
+ });
+
+ const resultsKey = Object.keys(results).find(
+ // @ts-expect-error
+ (key) => !('error' in results[key])
+ );
+ if (!resultsKey) {
+ throw new Error('No valid results found for domain ' + domain);
+ }
+ const firstResult = results[resultsKey] as WhoisSearchResult;
+
+ return {
+ registrar: firstResult['Registrar']?.toString() || 'Unavailable',
+ createdAt:
+ firstResult && 'Created Date' in firstResult
+ ? new Date(firstResult['Created Date'].toString()).toLocaleDateString(
+ 'en-US'
+ )
+ : 'Unavailable',
+ dnssec: firstResult['DNSSEC']?.toString() || 'Unavailable',
+ };
+ } catch (error) {
+ console.error(error);
+ return {
+ registrar: 'Unavailable',
+ createdAt: 'Unavailable',
+ dnssec: 'Unavailable',
+ };
+ }
+};
+
const WhoisQuickInfo: FC<WhoisQuickInfoProps> = async ({ domain }) => {
- const results = await whoiser(domain, {
- timeout: 5000,
- });
- const firstResult = results[
- // @ts-expect-error
- Object.keys(results).filter((key) => !('error' in results[key]))[0]
- ] as WhoisSearchResult;
+ const results = await getSummary(domain);
return (
<div className="my-8 flex gap-8">
<div>
<h3 className="text-xs text-muted-foreground">Registrar</h3>
- <p className="text-sm">
- {firstResult && 'Registrar' in firstResult
- ? firstResult['Registrar'].toString()
- : 'Unavailable'}
- </p>
+ <p className="text-sm">{results.registrar}</p>
</div>
<div>
<h3 className="text-xs text-muted-foreground">Creation Date</h3>
- <p className="text-sm">
- {firstResult && 'Created Date' in firstResult
- ? new Date(
- firstResult['Created Date'].toString()
- ).toLocaleDateString('en-US')
- : 'Unavailable'}
- </p>
+ <p className="text-sm">{results.createdAt}</p>
</div>
<div>
<h3 className="text-xs text-muted-foreground">DNSSEC</h3>
- <p className="text-sm">
- {firstResult && 'DNSSEC' in firstResult
- ? firstResult['DNSSEC'].toString()
- : 'Unavailable'}
- </p>
+ <p className="text-sm">{results.dnssec}</p>
</div>
</div>
);