Skip to content

Full Toolkit for Next-Level Domain Analysis

Add export button on subdomains page 💾

Felix Wotschofsky6b611debfdd5
diff --git a/app/lookup/[domain]/_components/icon-alert.tsx b/app/lookup/[domain]/_components/icon-alert.tsx
index 7df34b9..b324eb9 100644
--- a/app/lookup/[domain]/_components/icon-alert.tsx
+++ b/app/lookup/[domain]/_components/icon-alert.tsx
@@ -18,7 +18,7 @@ export const IconAlert: FC<IconAlertProps> = ({
title,
children,
}) => (
- <Alert className={cn('mx-auto max-w-max', className)}>
+ <Alert className={cn('max-w-max', className)}>
<Icon className="h-4 w-4" />
<AlertTitle>{title}</AlertTitle>
<AlertDescription>{children}</AlertDescription>
diff --git a/app/lookup/[domain]/_components/share-button.tsx b/app/lookup/[domain]/_components/share-button.tsx
index a70aab1..5b954ab 100644
--- a/app/lookup/[domain]/_components/share-button.tsx
+++ b/app/lookup/[domain]/_components/share-button.tsx
@@ -1,6 +1,6 @@
'use client';
-import { ShareIcon } from 'lucide-react';
+import { Share2Icon } from 'lucide-react';
import { usePlausible } from 'next-plausible';
import { type FC, useCallback } from 'react';
import { toast } from 'sonner';
@@ -35,7 +35,7 @@ export const ShareButton: FC = () => {
onClick={onClick}
aria-label="Share"
>
- <ShareIcon />
+ <Share2Icon />
</Button>
);
};
diff --git a/app/lookup/[domain]/certs/layout.tsx b/app/lookup/[domain]/certs/layout.tsx
index dd9de9f..8e59f70 100644
--- a/app/lookup/[domain]/certs/layout.tsx
+++ b/app/lookup/[domain]/certs/layout.tsx
@@ -9,7 +9,7 @@ type CertsLayoutProps = {
const CertsLayout: FC<CertsLayoutProps> = ({ children }) => (
<>
- <IconAlert className="my-12" icon={InfoIcon} title="How it works">
+ <IconAlert className="mx-auto my-12" icon={InfoIcon} title="How it works">
Every certificate issued for a domain by a trusted CA{' '}
<a
className="underline decoration-dotted underline-offset-4"
diff --git a/app/lookup/[domain]/map/page.tsx b/app/lookup/[domain]/map/page.tsx
index b9f1d5b..a0dbe04 100644
--- a/app/lookup/[domain]/map/page.tsx
+++ b/app/lookup/[domain]/map/page.tsx
@@ -38,7 +38,7 @@ const MapResultsPage: FC<MapResultsPageProps> = async ({
console.log('Bot detected, blocking request, UA:', userAgent);
return (
<IconAlert
- className="mt-24"
+ className="mx-auto mt-24"
icon={ShieldAlertIcon}
title="Bot or crawler detected!"
>
@@ -60,7 +60,7 @@ const MapResultsPage: FC<MapResultsPageProps> = async ({
<>
{hasDifferences ? (
<IconAlert
- className="mt-12"
+ className="mx-auto mt-12"
icon={InfoIcon}
title="Different records detected!"
>
@@ -71,7 +71,7 @@ const MapResultsPage: FC<MapResultsPageProps> = async ({
</IconAlert>
) : (
<IconAlert
- className="mt-12"
+ className="mx-auto mt-12"
icon={CheckCircleIcon}
title="All records are the same!"
>
diff --git a/app/lookup/[domain]/subdomains/_components/info-alert.tsx b/app/lookup/[domain]/subdomains/_components/info-alert.tsx
new file mode 100644
index 0000000..7b5fa53
--- /dev/null
+++ b/app/lookup/[domain]/subdomains/_components/info-alert.tsx
@@ -0,0 +1,28 @@
+import { InfoIcon } from 'lucide-react';
+import Link from 'next/link';
+import type { FC } from 'react';
+
+import { IconAlert } from '../../_components/icon-alert';
+
+type SubdomainsInfoAlertProps = {
+ domain?: string;
+};
+
+export const SubdomainsInfoAlert: FC<SubdomainsInfoAlertProps> = ({
+ domain,
+}) => (
+ <IconAlert icon={InfoIcon} title="How it works">
+ This is a deduplicated list of all subdomains found in the{' '}
+ {domain ? (
+ <Link
+ className="underline decoration-dotted underline-offset-4"
+ href={`/lookup/${domain}/certs`}
+ >
+ certificate transparency logs
+ </Link>
+ ) : (
+ 'certificate transparency logs'
+ )}{' '}
+ for this domain.
+ </IconAlert>
+);
diff --git a/app/lookup/[domain]/subdomains/layout.tsx b/app/lookup/[domain]/subdomains/layout.tsx
deleted file mode 100644
index a536676..0000000
--- a/app/lookup/[domain]/subdomains/layout.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import { InfoIcon } from 'lucide-react';
-import Link from 'next/link';
-import type { FC, ReactNode } from 'react';
-
-import { IconAlert } from '../_components/icon-alert';
-
-type SubdomainsLayoutProps = {
- children: ReactNode;
- params: {
- domain: string;
- };
-};
-
-const SubdomainsLayout: FC<SubdomainsLayoutProps> = ({
- children,
- params: { domain },
-}) => (
- <>
- <IconAlert className="my-12" icon={InfoIcon} title="How it works">
- This is a deduplicated list of all subdomains found in the{' '}
- <Link
- className="underline decoration-dotted underline-offset-4"
- href={`/lookup/${domain}/certs`}
- >
- certificate transparency logs
- </Link>{' '}
- for this domain.
- </IconAlert>
- {children}
- </>
-);
-
-export default SubdomainsLayout;
diff --git a/app/lookup/[domain]/subdomains/loading.tsx b/app/lookup/[domain]/subdomains/loading.tsx
index 6d64766..a06b57b 100644
--- a/app/lookup/[domain]/subdomains/loading.tsx
+++ b/app/lookup/[domain]/subdomains/loading.tsx
@@ -1,5 +1,7 @@
+import { ShareIcon } from 'lucide-react';
import type { FC } from 'react';
+import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import {
Table,
@@ -10,32 +12,43 @@ import {
TableRow,
} from '@/components/ui/table';
+import { SubdomainsInfoAlert } from './_components/info-alert';
+
const SubdomainsLoading: FC = () => (
- <Table>
- <TableHeader>
- <TableRow className="hover:bg-transparent">
- <TableHead className="pl-0">Domain Name</TableHead>
- <TableHead>First seen</TableHead>
- <TableHead className="pr-0">Still exists</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {Array.from({ length: 8 }).map(() => (
- // eslint-disable-next-line react/jsx-key
+ <>
+ <div className="my-12 flex items-center justify-between">
+ <SubdomainsInfoAlert />
+ <Button variant="outline" disabled>
+ <ShareIcon className="mr-2 h-4 w-4" /> Export
+ </Button>
+ </div>
+
+ <Table>
+ <TableHeader>
<TableRow className="hover:bg-transparent">
- <TableCell className="pl-0">
- <Skeleton className="h-5 w-64 rounded-sm" />
- </TableCell>
- <TableCell>
- <Skeleton className="h-5 w-80 rounded-sm" />
- </TableCell>
- <TableCell className="pr-0">
- <Skeleton className="h-5 w-5 rounded-sm" />
- </TableCell>
+ <TableHead className="pl-0">Domain Name</TableHead>
+ <TableHead>First seen</TableHead>
+ <TableHead className="pr-0">Still exists</TableHead>
</TableRow>
- ))}
- </TableBody>
- </Table>
+ </TableHeader>
+ <TableBody>
+ {Array.from({ length: 8 }).map(() => (
+ // eslint-disable-next-line react/jsx-key
+ <TableRow className="hover:bg-transparent">
+ <TableCell className="pl-0">
+ <Skeleton className="h-5 w-64 rounded-sm" />
+ </TableCell>
+ <TableCell>
+ <Skeleton className="h-5 w-80 rounded-sm" />
+ </TableCell>
+ <TableCell className="pr-0">
+ <Skeleton className="h-5 w-5 rounded-sm" />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </>
);
export default SubdomainsLoading;
diff --git a/app/lookup/[domain]/subdomains/page.tsx b/app/lookup/[domain]/subdomains/page.tsx
index e2e7cad..7cc9987 100644
--- a/app/lookup/[domain]/subdomains/page.tsx
+++ b/app/lookup/[domain]/subdomains/page.tsx
@@ -1,9 +1,14 @@
+import { ShareIcon } from 'lucide-react';
import type { Metadata } from 'next';
import type { FC } from 'react';
+import { Button } from '@/components/ui/button';
+
+import { generateCsv } from '@/lib/csv';
import { CloudflareDoHResolver } from '@/lib/resolvers/cloudflare';
import { findSubdomains } from '@/lib/subdomains';
+import { SubdomainsInfoAlert } from './_components/info-alert';
import { SubdomainsTable } from './_components/table';
export const runtime = 'edge';
@@ -33,6 +38,26 @@ const SubdomainsResultsPage: FC<SubdomainsResultsPageProps> = async ({
const { results, detailsReduced, detailedResultsLimit } =
await findSubdomains(domain, new CloudflareDoHResolver());
+ const exportFileName = `Domain Digger Subdomains Export ${domain.replaceAll(
+ '.',
+ '_',
+ )}.csv`;
+ const csv = generateCsv(
+ results
+ .toSorted((a, b) => b.firstSeen.getTime() - a.firstSeen.getTime())
+ .map((r) => ({
+ Domain: r.domain,
+ 'First seen': r.firstSeen.toISOString(),
+ 'Still exists':
+ r.stillExists === true
+ ? 'yes'
+ : r.stillExists === false
+ ? 'no'
+ : 'unknown',
+ })),
+ );
+ const encodedCsv = encodeURIComponent(csv);
+
if (!results.length) {
return (
<p className="mt-8 text-center text-muted-foreground">
@@ -43,6 +68,27 @@ const SubdomainsResultsPage: FC<SubdomainsResultsPageProps> = async ({
return (
<>
+ <div className="my-12 flex items-center justify-between">
+ <SubdomainsInfoAlert domain={domain} />
+ <Button
+ className={[
+ `plausible-event-name=Export`,
+ `plausible-event-type=Subdomains`,
+ `plausible-event-domain=${domain}`,
+ ].join(' ')}
+ variant="outline"
+ disabled={!results.length}
+ asChild
+ >
+ <a
+ href={`data:text/csv;charset=utf-8,${encodedCsv}`}
+ download={exportFileName}
+ >
+ <ShareIcon className="mr-2 h-4 w-4" /> Export
+ </a>
+ </Button>
+ </div>
+
<SubdomainsTable
results={results}
detailedResultsLimit={detailedResultsLimit}
diff --git a/lib/csv.test.ts b/lib/csv.test.ts
new file mode 100644
index 0000000..a5477bb
--- /dev/null
+++ b/lib/csv.test.ts
@@ -0,0 +1,49 @@
+import { describe, expect, it } from 'vitest';
+
+import { generateCsv } from './csv';
+
+describe('generateCsv', () => {
+ it('should generate a CSV string from an array of objects', () => {
+ const data = [
+ { name: 'John', age: 30, city: 'New York' },
+ { name: 'Alice', age: 25, city: 'London' },
+ { name: 'Bob', age: 35, city: 'Paris' },
+ ];
+
+ const expected =
+ 'name,age,city\nJohn,30,New York\nAlice,25,London\nBob,35,Paris';
+ expect(generateCsv(data)).toBe(expected);
+ });
+
+ it('should handle empty arrays', () => {
+ const data: Record<string, any>[] = [];
+ expect(generateCsv(data)).toBe('');
+ });
+
+ it('should handle arrays with a single object', () => {
+ const data = [{ key: 'value' }];
+ expect(generateCsv(data)).toBe('key\nvalue');
+ });
+
+ it('should handle objects with different keys', () => {
+ const data = [
+ { a: 1, b: 2 },
+ { b: 3, c: 4 },
+ { a: 5, c: 6 },
+ ];
+
+ const expected = 'a,b\n1,2\n,3\n5,';
+ expect(generateCsv(data)).toBe(expected);
+ });
+
+ it('should handle objects with nested structures', () => {
+ const data = [
+ { name: 'John', details: { age: 30, city: 'New York' } },
+ { name: 'Alice', details: { age: 25, city: 'London' } },
+ ];
+
+ const expected =
+ 'name,details\nJohn,[object Object]\nAlice,[object Object]';
+ expect(generateCsv(data)).toBe(expected);
+ });
+});
diff --git a/lib/csv.ts b/lib/csv.ts
new file mode 100644
index 0000000..320b890
--- /dev/null
+++ b/lib/csv.ts
@@ -0,0 +1,9 @@
+export const generateCsv = <T extends Record<string, any>>(data: T[]) => {
+ if (!data.length) return '';
+ const columns = Object.keys(data[0]);
+ const header = columns.join(',');
+ const rows = data.map((row) =>
+ columns.map((column) => row[column]).join(','),
+ );
+ return [header, ...rows].join('\n');
+};