Skip to content

Full Toolkit for Next-Level Domain Analysis

Add Google and Cloudflare DNS resolvers 🕵️‍♀️

Felix Wotschofskydf88673d44ed
diff --git a/app/lookup/[domain]/page.tsx b/app/lookup/[domain]/page.tsx
index 4ddc018..91cf99a 100644
--- a/app/lookup/[domain]/page.tsx
+++ b/app/lookup/[domain]/page.tsx
@@ -1,18 +1,40 @@
import type { FC } from 'react';
import DnsTable from '@/components/DnsTable';
+import ResolverSelector from '@/components/ResolverSelector';
import AuthoritativeResolver from '@/lib/resolvers/AuthoritativeResolver';
+import CloudflareDoHResolver from '@/lib/resolvers/CloudflareDoHResolver';
+import GoogleDoHResolver from '@/lib/resolvers/GoogleDoHResolver';
+
+const getResolver = (resolverName: string | undefined) => {
+ switch (resolverName) {
+ case 'cloudflare':
+ return CloudflareDoHResolver;
+ case 'google':
+ return GoogleDoHResolver;
+ default:
+ return AuthoritativeResolver;
+ }
+};
type LookupDomainProps = {
params: {
domain: string;
};
+ searchParams: {
+ resolver?: string;
+ };
};
export const fetchCache = 'default-no-store';
-const LookupDomain: FC<LookupDomainProps> = async ({ params: { domain } }) => {
- const lookup = new AuthoritativeResolver();
+const LookupDomain: FC<LookupDomainProps> = async ({
+ params: { domain },
+ searchParams: { resolver: resolverName },
+}) => {
+ const Resolver = getResolver(resolverName);
+
+ const lookup = new Resolver();
const records = await lookup.resolveAllRecords(domain);
return (
@@ -24,7 +46,13 @@ const LookupDomain: FC<LookupDomainProps> = async ({ params: { domain } }) => {
No DNS records found!
</p>
) : (
- <DnsTable records={records} />
+ <div>
+ <div className="flex flex-col gap-1">
+ <span className="text-sm text-muted-foreground">Resolver</span>
+ <ResolverSelector />
+ </div>
+ <DnsTable records={records} />
+ </div>
)}
</>
);
diff --git a/components/ResolverSelector.tsx b/components/ResolverSelector.tsx
new file mode 100644
index 0000000..a3d8e0e
--- /dev/null
+++ b/components/ResolverSelector.tsx
@@ -0,0 +1,56 @@
+'use client';
+
+import { usePathname, useRouter, useSearchParams } from 'next/navigation';
+import { FC, useCallback } from 'react';
+
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from '@/components/ui/select';
+
+type ResolverSelectorProps = {
+ initialValue?: string;
+};
+
+const ResolverSelector: FC<ResolverSelectorProps> = ({ initialValue }) => {
+ const router = useRouter();
+ const pathname = usePathname();
+ const searchParams = useSearchParams();
+
+ const onValueChange = useCallback(
+ (value: string) => {
+ const current = new URLSearchParams(Array.from(searchParams.entries()));
+
+ if (!value || value === 'authoritative') {
+ current.delete('resolver');
+ } else {
+ current.set('resolver', value);
+ }
+
+ const search = current.toString();
+ router.push(`${pathname}${search ? `?${search}` : ''}`);
+ },
+ [router, pathname, searchParams]
+ );
+
+ return (
+ <Select
+ defaultValue={initialValue || 'authoritative'}
+ onValueChange={onValueChange}
+ >
+ <SelectTrigger className="w-[180px]">
+ <SelectValue placeholder="Resolver" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="authoritative">Authoritative</SelectItem>
+ <SelectItem value="google">Google</SelectItem>
+ <SelectItem value="cloudflare">Cloudflare</SelectItem>
+ </SelectContent>
+ </Select>
+ );
+};
+
+export default ResolverSelector;
diff --git a/components/ui/select.tsx b/components/ui/select.tsx
new file mode 100644
index 0000000..f6338bd
--- /dev/null
+++ b/components/ui/select.tsx
@@ -0,0 +1,160 @@
+'use client';
+
+import * as SelectPrimitive from '@radix-ui/react-select';
+import * as React from 'react';
+import { Check, ChevronDown, ChevronUp } from 'lucide-react';
+
+import { cn } from '@/lib/utils';
+
+const Select = SelectPrimitive.Root;
+
+const SelectGroup = SelectPrimitive.Group;
+
+const SelectValue = SelectPrimitive.Value;
+
+const SelectTrigger = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
+>(({ className, children, ...props }, ref) => (
+ <SelectPrimitive.Trigger
+ ref={ref}
+ className={cn(
+ 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
+ className
+ )}
+ {...props}
+ >
+ {children}
+ <SelectPrimitive.Icon asChild>
+ <ChevronDown className="h-4 w-4 opacity-50" />
+ </SelectPrimitive.Icon>
+ </SelectPrimitive.Trigger>
+));
+SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
+
+const SelectScrollUpButton = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.ScrollUpButton
+ ref={ref}
+ className={cn(
+ 'flex cursor-default items-center justify-center py-1',
+ className
+ )}
+ {...props}
+ >
+ <ChevronUp className="h-4 w-4" />
+ </SelectPrimitive.ScrollUpButton>
+));
+SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
+
+const SelectScrollDownButton = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.ScrollDownButton
+ ref={ref}
+ className={cn(
+ 'flex cursor-default items-center justify-center py-1',
+ className
+ )}
+ {...props}
+ >
+ <ChevronDown className="h-4 w-4" />
+ </SelectPrimitive.ScrollDownButton>
+));
+SelectScrollDownButton.displayName =
+ SelectPrimitive.ScrollDownButton.displayName;
+
+const SelectContent = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
+>(({ className, children, position = 'popper', ...props }, ref) => (
+ <SelectPrimitive.Portal>
+ <SelectPrimitive.Content
+ ref={ref}
+ className={cn(
+ 'relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
+ position === 'popper' &&
+ 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
+ className
+ )}
+ position={position}
+ {...props}
+ >
+ <SelectScrollUpButton />
+ <SelectPrimitive.Viewport
+ className={cn(
+ 'p-1',
+ position === 'popper' &&
+ 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
+ )}
+ >
+ {children}
+ </SelectPrimitive.Viewport>
+ <SelectScrollDownButton />
+ </SelectPrimitive.Content>
+ </SelectPrimitive.Portal>
+));
+SelectContent.displayName = SelectPrimitive.Content.displayName;
+
+const SelectLabel = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Label>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.Label
+ ref={ref}
+ className={cn('py-1.5 pl-8 pr-2 text-sm font-semibold', className)}
+ {...props}
+ />
+));
+SelectLabel.displayName = SelectPrimitive.Label.displayName;
+
+const SelectItem = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Item>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
+>(({ className, children, ...props }, ref) => (
+ <SelectPrimitive.Item
+ ref={ref}
+ className={cn(
+ 'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
+ className
+ )}
+ {...props}
+ >
+ <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
+ <SelectPrimitive.ItemIndicator>
+ <Check className="h-4 w-4" />
+ </SelectPrimitive.ItemIndicator>
+ </span>
+
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
+ </SelectPrimitive.Item>
+));
+SelectItem.displayName = SelectPrimitive.Item.displayName;
+
+const SelectSeparator = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Separator>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.Separator
+ ref={ref}
+ className={cn('-mx-1 my-1 h-px bg-muted', className)}
+ {...props}
+ />
+));
+SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
+
+export {
+ Select,
+ SelectGroup,
+ SelectValue,
+ SelectTrigger,
+ SelectContent,
+ SelectLabel,
+ SelectItem,
+ SelectSeparator,
+ SelectScrollUpButton,
+ SelectScrollDownButton,
+};
diff --git a/lib/resolvers/CloudflareDoHResolver.ts b/lib/resolvers/CloudflareDoHResolver.ts
new file mode 100644
index 0000000..e081430
--- /dev/null
+++ b/lib/resolvers/CloudflareDoHResolver.ts
@@ -0,0 +1,61 @@
+import DnsResolver, {
+ type RawRecord,
+ RECORD_TYPES_BY_DECIMAL,
+ type RecordType,
+} from './DnsResolver';
+
+type DoHResponse = {
+ Status: number;
+ TC: boolean;
+ RD: boolean;
+ RA: boolean;
+ AD: boolean;
+ CD: boolean;
+ Question: {
+ name: string;
+ type: number;
+ }[];
+ Answer?: {
+ name: string;
+ type: number;
+ TTL: number;
+ data: string;
+ }[];
+ Authority?: {
+ name: string;
+ type: number;
+ TTL: number;
+ data: string;
+ }[];
+};
+
+export default class CloudflareDoHResolver extends DnsResolver {
+ public async resolveRecordType(
+ domain: string,
+ type: RecordType
+ ): Promise<RawRecord[]> {
+ const response = await fetch(
+ `https://cloudflare-dns.com/dns-query?name=${domain}&type=${type}`,
+ {
+ method: 'GET',
+ headers: { Accept: 'application/dns-json' },
+ }
+ );
+ if (!response.ok)
+ throw new Error(`Bad response from Cloudflare: ${response.statusText}`);
+ const results = (await response.json()) as DoHResponse;
+
+ return (
+ results.Answer?.map((answer) => ({
+ name: answer.name,
+ type:
+ answer.type in RECORD_TYPES_BY_DECIMAL
+ ? // @ts-expect-error
+ RECORD_TYPES_BY_DECIMAL[answer.type]
+ : 'UNKNOWN',
+ TTL: answer.TTL,
+ data: answer.data,
+ })) || []
+ );
+ }
+}
diff --git a/lib/resolvers/DnsResolver.ts b/lib/resolvers/DnsResolver.ts
index a741440..9e8c591 100644
--- a/lib/resolvers/DnsResolver.ts
+++ b/lib/resolvers/DnsResolver.ts
@@ -1,4 +1,4 @@
-const RECORD_TYPES = [
+export const RECORD_TYPES = [
'A',
'AAAA',
'CAA',
@@ -14,6 +14,22 @@ const RECORD_TYPES = [
'TXT',
] as const;
+export const RECORD_TYPES_BY_DECIMAL = {
+ 1: 'A',
+ 28: 'AAAA',
+ 257: 'CAA',
+ 5: 'CNAME',
+ 48: 'DNSKEY',
+ 43: 'DS',
+ 15: 'MX',
+ 35: 'NAPTR',
+ 2: 'NS',
+ 12: 'PTR',
+ 6: 'SOA',
+ 33: 'SRV',
+ 16: 'TXT',
+} as const;
+
export type RecordType = (typeof RECORD_TYPES)[number];
export type RawRecord = {
diff --git a/lib/resolvers/GoogleDoHResolver.ts b/lib/resolvers/GoogleDoHResolver.ts
new file mode 100644
index 0000000..c9a8861
--- /dev/null
+++ b/lib/resolvers/GoogleDoHResolver.ts
@@ -0,0 +1,61 @@
+import DnsResolver, {
+ type RawRecord,
+ RECORD_TYPES_BY_DECIMAL,
+ type RecordType,
+} from './DnsResolver';
+
+type DoHResponse = {
+ Status: number;
+ TC: boolean;
+ RD: boolean;
+ RA: boolean;
+ AD: boolean;
+ CD: boolean;
+ Question: {
+ name: string;
+ type: number;
+ }[];
+ Answer?: {
+ name: string;
+ type: number;
+ TTL: number;
+ data: string;
+ }[];
+ Authority?: {
+ name: string;
+ type: number;
+ TTL: number;
+ data: string;
+ }[];
+};
+
+export default class GoogleDoHResolver extends DnsResolver {
+ public async resolveRecordType(
+ domain: string,
+ type: RecordType
+ ): Promise<RawRecord[]> {
+ const response = await fetch(
+ `https://dns.google/resolve?name=${domain}&type=${type}`,
+ {
+ method: 'GET',
+ headers: { Accept: 'application/json' },
+ }
+ );
+ if (!response.ok)
+ throw new Error(`Bad response from Google: ${response.statusText}`);
+ const results = (await response.json()) as DoHResponse;
+
+ return (
+ results.Answer?.map((answer) => ({
+ name: answer.name,
+ type:
+ answer.type in RECORD_TYPES_BY_DECIMAL
+ ? // @ts-expect-error
+ RECORD_TYPES_BY_DECIMAL[answer.type]
+ : 'UNKNOWN',
+ TTL: answer.TTL,
+ data: answer.data,
+ })) || []
+ );
+ }
+}
diff --git a/package.json b/package.json
index 9724a6f..14a08b8 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
+ "@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2d4188f..71a936e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -14,6 +14,9 @@ dependencies:
'@radix-ui/react-dropdown-menu':
specifier: ^2.0.6
+ '@radix-ui/react-select':
+ specifier: ^2.0.0
'@radix-ui/react-slot':
specifier: ^1.0.2
version: 1.0.2(@types/[email protected])([email protected])
@@ -1692,6 +1695,12 @@ packages:
'@nodelib/fs.scandir': 2.1.5
fastq: 1.15.0
+ /@radix-ui/[email protected]:
+ resolution: {integrity: sha512-T5gIdVO2mmPW3NNhjNgEP3cqMXjXL9UbO0BzWcXfvdBs+BohbQxvd/K5hSVKmn9/lbTdsQVKbUcP5WLCwvUbBg==}
+ dependencies:
+ '@babel/runtime': 7.23.6
+ dev: false
+
/@radix-ui/[email protected]:
resolution: {integrity: sha512-yQ8oGX2GVsEYMWGxcovu1uGWPCxV5BFfeeYxqPmuAzUyLT9qmaMXSAhXpb0WrspIeqYzdJpkh2vHModJPgRIaw==}
dependencies:
@@ -2110,6 +2119,47 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ resolution: {integrity: sha512-RH5b7af4oHtkcHS7pG6Sgv5rk5Wxa7XI8W5gvB1N/yiuDGZxko1ynvOiVhFM7Cis2A8zxF9bTOUVbRDzPepe6w==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.23.6
+ '@radix-ui/number': 1.0.1
+ '@radix-ui/primitive': 1.0.1
+ '@radix-ui/react-collection': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-compose-refs': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-direction': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-dismissable-layer': 1.0.5(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-focus-guards': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-focus-scope': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-id': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-popper': 1.1.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-portal': 1.0.4(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@radix-ui/react-slot': 1.0.2(@types/[email protected])([email protected])
+ '@radix-ui/react-use-callback-ref': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-use-controllable-state': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-use-layout-effect': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-use-previous': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-visually-hidden': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@types/react': 18.2.43
+ '@types/react-dom': 18.2.17
+ aria-hidden: 1.2.3
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ react-remove-scroll: 2.5.5(@types/[email protected])([email protected])
+ dev: false
+
resolution: {integrity: sha512-YeTpuq4deV+6DusvVUW4ivBgnkHwECUu0BiN43L5UCDFgdhsRUWAghhTF5MbvNTPzmiFOx90asDSUjWuCNapwg==}
peerDependencies:
@@ -2243,6 +2293,20 @@ packages:
react: 18.2.0
dev: false
+ resolution: {integrity: sha512-cV5La9DPwiQ7S0gf/0qiD6YgNqM5Fk97Kdrlc5yBcrF3jyEZQwm7vYFqMo4IfeHgJXsRaMvLABFtd0OVEmZhDw==}
+ peerDependencies:
+ '@types/react': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.23.6
+ '@types/react': 18.2.43
+ react: 18.2.0
+ dev: false
+
resolution: {integrity: sha512-Cq5DLuSiuYVKNU8orzJMbl15TXilTnJKUCltMVQg53BQOF1/C5toAaGrowkgksdBQ9H+SRL23g0HDmg9tvmxXw==}
peerDependencies: